instance_find


Description

All instances have a unique identifier (id) which can be used to modify and manipulate them while a game is running, but you may not always know what the id for a specific instance is and so this function can help as you can use it to iterate through all of them to find what you need. You specify the object that you want to find the instance of and a number, and if there is an instance at that position in the instance list then the function returns the id of that instance, and if not it returns the special keyword noone. You can also use the keyword all to iterate through all the instances in a room, as well as a parent object to iterate through all the instances that are part of that parent / child hierarchy and you can even specify an instance itself (if you have its id) as a check to see if it actually exists in the current room. Please note that as instances are sorted in an arbitrary manner, there is no specific order to how the instances are checked by this function, and any instance can be in any position.

The maximum value for "n" in this function would be


Syntax:

instance_find(obj, n);


Arguments:

Argument Description
obj The object to find the nth instance of
n The number of the instance to find.


Returns:

Real (either an instance ID value or the keyword noone)


Example:

var i;
for (i = 0; i < instance_number(obj_Enemy); i += 1)
   {
   enemy[i] = instance_find(obj_Enemy,i);
   }

The above code will use a for loop to iterate through all the instances of "obj_Enemy" and store their id in the array "enemy[]".