Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I am making a small puzzle based game. I want the number of instances of an object to be equal to the ammo count plus 2.

Each time a new room is loaded, the main object's creation method with run this script:

var ammo = instance_count(jellyfish)+2;

Then each time a bullet is fired, I subtract one. When there is no ammo left, the player goes to the 'failure' room.

However, I get the error: Unknown function or script: instance_count.

I have see this script on Google, but am not sure if it has deprecated or not. Is there a way I can do this?

share|improve this question

2 Answers 2

up vote 3 down vote accepted

The function you want is instance_number(obj) (documentation found here).

This functions returns the number of instances of a object that exist in the current room.

share|improve this answer

if you used instance_count you could do

share|improve this answer
Can you edit your answer to include the documentation surrounding the instance_count property? I don't see it. –  Byte56 Feb 20 at 23:34
instance_count returns the all the active instances in the room: instance_count –  xpy Mar 15 at 10:46

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.