How do I Count the number of an instance

0 favourites
  • 6 posts
From the Asset Store
An educational game for counting pictures. An easy to use template for developers to build larger games
  • Hello all,

    Sorry if this has been explained elsewhere but I can't find it. I'm not a programmer, and have only had the program a week so I'm stumped. I have an enemy sprite called "SnailEnemy" and a goal where I want them to get to.

    How do I:

    1) Start of Layout, count the number of "SnailEnemy" to create "SnailEnemyCount" (Instance Variable on Goal)

    2) Subtract 1 from "SnailEnemyCount" whenever it collides with "Goal"

    3) If "SnailEnemyCount = 0", restart Layout

    I could set the SnailEnemyCount manually to the number each layout starts with, but I want the system to handle it instead. When I run the game, on the first restart I get the message:

    "The Instance being inspected ('Goal' UID 18) was destroyed"

    I don't have any actions that should destroy the Goal so I don't know why it's breaking. It remains visible even while the system continually tries to restart. Thanks for any and all responses.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I would make a global variable called "snailEnemyCount" by right clicking in the event editor and choosing add global variable

    then make an event "on system start." set global/local choose "snailEnemyCount" and then type snailEnemy.Count

    then as new event snailEnemy - is overlaping and then choose goal.

    system set global/local snailEnemyCount = snailEnemyCount-1

    finally an event for snailEnemyCount = 0 restart layout

    hope I explained it well and hope it helps. Also I have no idea about your bug.

  • Thanks for the assistance

  • You should be able to get what you want with NO variables at all just have a System compare to values SnailEneamy.count = 0 it's that simple

  • That would only work for what he wants if he plans to destroy the snailEnemy the second it touches the goal. I imagined he wanted the snailEnemy to continue existing maybe do a victory dance or something while the global count of how many are in the race can still tick downwards.

  • There will be other conditions that can destroy the snails without it leading to victory so that suggestion won't work. Thanks for the suggestion though

    The bug has returned even while using Global Variables. It seems to be fairly random.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)