ObjectsAlso objects can be manipulated and created during the game play. NEVER change or delete an object for which there are instances. This can lead to unexpected effects as certain object properties are stored with the instance and, hence, changing them in the object will not have the desired effect.
object_set_sprite(ind,spr) Sets the sprite of the object with the given index. Use -1 to remove the current sprite from the object.
object_set_solid(ind,solid) Sets whether instances created of the object must default be solid (true or false).
object_set_visible(ind,vis) Sets whether instances created of the object must default be visible (true or false).
object_set_depth(ind,depth) Sets the default depth of instances created of the object.
object_set_persistent(ind,pers) Sets whether instances created of the object must default be persistent (true or false).
object_set_mask(ind,spr) Sets the sprite mask of the object with the given index. Use -1 to set the mask to be the sprite of the object.
object_set_parent(ind,obj) Sets the parent of the object. Use -1 to not have a parent. Changing the parent changes the behavior of instances of the object.
The following routines are useful for creating objects on the fly. As with all resource changing routines, be very careful that you don't create new objects all the time.
object_add() Adds a new object. It returns the index of the object. You can now use this index in the routines above to set certain properties of the object and then you can use the index to create instances of the object.
object_delete(ind) Deletes the object with the given index. Make sure no instances of the object exist in any of the rooms.
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.
object_event_clear(ind,evtype,evnumb) You can use this function to clear all the actions for a particular event.
Creating objects is in particular useful when you are designing scripts or action libraries. For example, an initialization script can create an object to display a text and another script can add such an object with a particular text. In this way you have a simple mechanism to display texts without the need to create objects using the standard interface.