Global variable problem

  • Hello guys,

    I have little problem. I am absolutely beginner so I am sorry if this sounds stupid.

    I have a global variable called enemies_number. The value of it is set to 5.

    And then when I hit some enemies I do like: enemies_number-1 and in conditions I also have this:

    <img src="http://img856.imageshack.us/img856/1002/enemiesn.jpg" border="0" />

    What I am trying to do is that until enemies_number is not 0 I can generate this "sprite 4" every 8 seconds. But what happened is that when my enemies_number is 0 sprite4 is still spawning even it should not. How come?

    Thank you

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • It's because of how events work.

    Event 10 (your "Every 8 seconds" count) is a sub event to event 9 (the blank event) which is true every tick.

    You should rather put in event 8 the conditions :

    System: Every 8 seconds

    System: enemies_number =not 0

    and put the actions of event 10 in event 8.

    This way, every 8 seconds C2 would test if "enemies_number" is different than 0, and if it is, it will spawn a new sprite.

    Else, the condition being false, the actions wouldn't be executed.

    Also you don't necessarily need a global variable to keep count of the instances number.

    Considering your object type is a sprite named "Enemy", you could instead of "System: enemies_number =not 0" having a "System: Compare two values" condition, its first field being "Enemy.count" not equal 0.

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