How do I track how many enemies are killed

1 favourites
  • 7 posts
From the Asset Store
Simple and easily editable template for a dynamic camera that zooms in and out based on how far apart the players are.
  • This seems like it would be something simple to do but maybe I'm approaching it the wrong way.

    I'd like for my game to track how many enemies are killed in a given room in order to clear it and open a door to proceed into the next room.

    Right now I have it so that when when an enemies health reaches 0 they are set to boolean "dead" = true and 1 is added to global variable "areaclear".

    I want it so when "areaclear" reaches say 10 for example this triggers a door to open and the player can move onto the next area.

    My problem is once an enemies health reaches 0 it triggers the add 1 to global variable 60+ times.

    I've tried using the 'trigger once if true' and also adding an action immediately after adding to the global variable to set the health to -1. I've also variations of this with a boolean check for "dead". None are working properly for me.

    Advice?

  • "trigger once if true" should work, you are probably not using it properly.

    You can do this without the "areaclear" variable:

    Enemy-> Is boolean variable Dead set 
          System->Compare two values -> Enemy.pickedCound>=10  :  Go to next level
    [/code:yp3rty5g]
    
    First event will pick all dead enemies.
    Second sub-event will compare number of picked instances.
  • I probably am using the "trigger once if true" wrong somewhere, the problem I was having was (all the same enemy type btw) if I killed two enemy at the same time it would register only once giving an inaccurate count.

    Your "pick" solution actually works great so thanks for that.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • In events where several object instances can be affected (like bullet collides with two enemies) I prefer to add another sub-event "For each Enemy". This often helps to prevent some weird and hard-to-detect bugs.

    Or if you need to make sure that each bullet should wound/kill only one instance of enemy, add "System->Pick random Enemy instance" as a sub-event.

  • That makes sense, I'll keep that in mind, thanks!

  • Easy just add Global variable and name it Enemy_Killed = 0

    in section, Enemy destroy add System add 1 to variable Enemy_Killed

    This should work fine

  • Yeah, using the "for each" condition is very handy. Especially when you're playing around with enemies. I think your problem has something to do with the enemies hp being connected. I can try to help you if you are still having problems with this.

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