instance_id

This read-only variable acts as an array that holds the ids of all active instances within the room. This means that if you have used any of the Instance Deactivate functions those instances that have been deactivated will not be included in this array.

NOTE This variable does not hold a real GML array, so you cannot run any array functions on it or serialise it (convert it to a string). The only operation you can run on it is returning a value at an index, with the instance_id[index] syntax.

As you cannot run array_length on this function, use instance_number(all) to get the number of instances in the room. Any entries outside of this range will return noone (-4).

 

Syntax:

instance_id[num];

 

Returns:

Object Instance

 

Example:

for (var i = 0; i < instance_count; i ++;)
{
    with (instance_id[i]) speed += 0.1;
}

The above code will loop through all instances within the room and add 0.1 to their speed.