(SOLVED) Problem with counting objects

I want to open the door after all enemies inside the room are killed. Currently my code counts each dead enemy too many times ( I assume around 60). If I put the Trigger once condition, it counts only first killed enemy.

In your condition, there is currently no indication about if the ennemi just died or is dead for long.
So there are many ways you could solve that.
The easiest, but maybe not most optimal, is to add a condition “animation of ennemi different than Death”

You can also use a boolean variable alive/dead,
Or your health variable, set it to -1 if dead, and add a condition, health /=-1… Well many ways, main thing is to record who’s already dead.

You can use number of items currently picked, similar to:

In this example, the tint change is just a visual to confirm an object has been clicked or all of them have been counted.

And instead of checking the boolean value, choose the enemies with health less than or equal to 0.

Hi again :slight_smile:

I’ve tried with changing animation before but I had it in separate condition. I got it to work properly now and will use this solution for the time being.

Could you explain how would I use boolean in the future? I assume boolean checks if the object is 0 or 1. But I’m not sure how would I check it in this example, since I don’t delete enemies after death.

Thank you very much for the help.

1 Like

Got it working with boolean as well. Thank you guys.

1 Like

So you know now, it’s ok?

Yup all good, thank you.

1 Like

@Bluzima Hi, would it be possible to get you to explain how to use the Boolean, please?

1 Like

Hi @Chinnonye I won’t explain better than the wiki i think.

A Boolean variable is a variable that has only 2 possible values, called true and false. The way it works is like value and string variables, except you have only true or false.

Hence it allows you to record a 2 possibilities information.

For example:

  • a character is dead or alive
  • the player has or has not glasses
  • the current state of the game is pause
  • this or that part of code has already been complete (helps to avoid repetition)
  • a character just died during this frame, and it’s death hasn’t been processed yet (that the case in this topic)

Well there are many case it’s more handy than other variables.

You can also toggle a Boolean, which means change its value without necessarily having to know what is this value, true or false.

1 Like

@Bluzima thank you very much especially with the examples. The wiki didnt share.

1 Like