Returns the number of active instances of a given object.



Argument Description
obj The object to total the number of instances of.

Returns: Real


With this function you can find out how many active instances of the specified object exists in the room. Please note that those instances which have been deactivated with the instance_deactivate functions will not be included in this check.


if instance_number(object_index) < 50    {
   instance_create(random(room_width), random(room_height), object_index);

The above code will check the number of instances that are created form the same object as the current instance and then if there are less than 50, create another one at a random position within the room.

Back: Instance Functions
Next: instance_place
© Copyright YoYo Games Ltd. 2018 All Rights Reserved