Jump to content


Photo

Object creation in code


  • Please log in to reply
6 replies to this topic

#1 smallworld188

smallworld188

    GMC Member

  • New Member
  • 120 posts
  • Version:GM8

Posted 30 November 2010 - 01:05 AM

Hello

I wanna know how to create an object in code...but i have no idea how.

So could anyone please show me how to create one in code?

All I know is that the easiest way to do this is by using a script.
  • 0

#2 runewake2

runewake2

    GMC Member

  • New Member
  • 204 posts

Posted 30 November 2010 - 01:58 AM

instance_create(x,y,obj_to_create);
  • 0

#3 johnbot2010

johnbot2010

    GMC Member

  • New Member
  • 141 posts

Posted 30 November 2010 - 02:16 AM

Do you mean creating instances of an object, or an object itself? If you want to create an instance, then you would use runeawake2's code.
If, however, you want to create a whole new object, in code, you would have to do something like this:
new_object = object_add();
object_set_sprite(new_object,sprite_of_new_object);
object_set_solid(new_object,solidness_of_new_object);
object_set_visible(new_object,visibility_of_new_object);
object_set_depth(new_object,depth_of_new_object);
object_set_persistent(new_object,persistence_of_new_object);
object_set_mask(new_object,mask_of_new_object);
object_set_parent(new_object,parent_of_new_object);
//Change the above variables that are the second arguments of the functions above (i.e. solidness_of_new_object should be changed to true or false).

Then, to add events to your new object, you would use:

object_event_add(ind,evtype,evnumb,codestr) To give the object a behavior we must define events for the object. You can only add code actions to events. You need to specify the object, the event type, the event number (use the constants that have been specified before for the event_perform() function). Finally you provide the code string that must be executed. You can add multiple code actions to each event.


  • 0

#4 smallworld188

smallworld188

    GMC Member

  • New Member
  • 120 posts
  • Version:GM8

Posted 30 November 2010 - 02:26 AM

um...ok as for adding events, i don't get the "codestring" part. Could you explain that part for me? plz?
  • 0

#5 johnbot2010

johnbot2010

    GMC Member

  • New Member
  • 141 posts

Posted 30 November 2010 - 02:58 AM

The script for the event of the object. Like in the create event for an object, you might set Hp to 100, so the codestring for it would just be
"Hp = 100;".
  • 0

#6 smallworld188

smallworld188

    GMC Member

  • New Member
  • 120 posts
  • Version:GM8

Posted 30 November 2010 - 03:26 AM

The script for the event of the object. Like in the create event for an object, you might set Hp to 100, so the codestring for it would just be
"Hp = 100;".

Ok...but what about making it do multiple actions in one event?
  • 0

#7 johnbot2010

johnbot2010

    GMC Member

  • New Member
  • 141 posts

Posted 30 November 2010 - 12:01 PM

Simple, just hit enter, and type in more code...
i.e. codestring would be something like:
hp = 10;
show_message("Object Created!");
if (hp = =10)
{
show_message("This will always happen.");
}

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users