How do I count number of enemies left?

2 favourites
  • 3 posts
From the Asset Store
A complete set of graphical user interface (GUI) to build 2D video games. With wood, nature, & jungle theme
  • My son (7th grade) is learning Construct 3 by watching online tutorials. Recently he had a problem as described below:

    • In the game, he spawns enemies every few seconds. A global variable is used tracking how many enemies are still alive.
    • A bomb can kill multiple enemies (by subtracting 3 from enemy health) at the same time if the enemies are in the explosion zone.
    • Once the enemies health reaches zero, the enemy count will subtract by 0.25

    The problem we had is that if the bomb kills lots of enemies (>6) at the same time, the global counter either did not change at all or only decrease by 0.25. The enemies did get destroyed correctly. The game ended up with the counter showing there were still enemies, but actually all enemies have been killed on the screen. When there were only a few enemies (<4) that got killed, the counter decreased as expected.

    Attached is a screen snapshot showing the enemy and bomb logic.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Would it be easier to use T1Z.count which is the number of enemies in the level? That way it's always correct and there is no possibility for bugs.

    To fix the current logic, adding a 'for each enemy' to the health condition should work.

  • Thank you, plinkie. Both solutions worked. Now we know each sprite has a counter build-in :) Thanks!

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