2
\$\begingroup\$

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?

\$\endgroup\$
4
\$\begingroup\$

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.

\$\endgroup\$
0
\$\begingroup\$

if you used instance_count you could do

jellyfish.instance_count+2
\$\endgroup\$
  • 1
    \$\begingroup\$ Can you edit your answer to include the documentation surrounding the instance_count property? I don't see it. \$\endgroup\$ – MichaelHouse Feb 20 '15 at 23:34
  • \$\begingroup\$ instance_count returns the all the active instances in the room: instance_count \$\endgroup\$ – xpy Mar 15 '15 at 10:46
0
\$\begingroup\$

I think it is because there is no jellyfish instances in the failure room. What you can do (I don't think this works in gamemaker 8.1, you actually have to use the room number, which is an integer (1, 2, 3, etc.)), but assuming you are using gamemaker studio you should use this, where failureroom is the name of the failure room:

if room != failureroom
    {var ammo = instance_count(jellyfish)+2}

In this script the curly brackets are not necessary, but if you have more lines of code in the test like maybe you set the health as well, you have to use it.

Example:

if room != failureroom
    {var ammo = instance_count(jellyfish)+2
    var health = instance_count(jellyfish)+2}

If you do:

if room != failureroom
    var ammo = instance_count(jellyfish)+2
    var health = instance_count(jellyfish)+2

It will always change the health, even if you're in the failure room, but it will only change the ammo if youre not in the failure room.

\$\endgroup\$
0
\$\begingroup\$

You should use instance_number(jellyfish) instead of instance_count. Instance_count are ALL objects and instance_number(obj) is the count of A SPECIFIED object.

\$\endgroup\$
  • \$\begingroup\$ Welcome to the site. Because this question was asked so long ago, your answer appeared in the review queue of late answers. Unfortunately, your answer repeats the answer that was accepted long ago, so there it does not add helpful information. If you want to reiterate that this solution helped you, vote up the accepted answer. Multiple identical answers don't improve the quality of information of the site. \$\endgroup\$ – Seth Battin Aug 23 '15 at 17:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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