Thursday 8 March 2012

Game Maker Tip #1

instance_exists(obj) is a fantastic function that returns true if an instance of the object exists. You can use a general object index (for example o_player), a specific instance id (e.g. player or 100421) or keywords like all. I use it frequently to check if an instance still exists before executing code involving that instance.


However, be careful. instance_exists(0) will always return true, because it interprets the 0 as being a reference to the first object created. Therefore if you have variables in your create events or elsewhere which will be used to store instance ids, initialise them with name=noone rather than name=0.

No comments:

Post a Comment