Trigger when there are no objects with a certain variable on the given layer

I have objects with a ‘state’ variable. The state can be ‘inactive’, or a number of other values (‘active’, ‘falling’, ‘moving’, etc.). These objects are also on two different layers: ‘red’ and ‘orange’.

I need to setup an event that’ll trigger when there are no objects on the ‘red’ layer with the ‘inactive’ state variable. There may still be objects on the ‘red’ layer with other states, and there may be ‘inactive’ objects on the ‘orange’ layer.

Here’s what I have so far:

All objects are ‘inactive’. The red ones are on the ‘red’ layer and the orange one is on the ‘orange’ layer (genius, right?).

When you click on any object, it’ll turn green and the state changes to ‘active’. The idea is that once all red objects are green (i.e. no more ‘inactive’ objects on the ‘red’ layer) the text ‘Game over’ will appear.

However I can’t work out how to check the layer as well as the state. I thought putting them both in the NOT condition would do it, but apparently not (no pun intended).

Any ideas?

Hey BWPanda,

Whipped up a quick example on the online editor with what it seems like you want. Have a look at it working Test Example (Space to check for any reds, and Z to remove them all).
In your scenario you would be checking for inactive not active states, but I am sure you get the idea.

There might be other ways to do it, but this one is pretty simple.

  1. Create a temp variable. (Set as false for default)
  2. Loop through each circle.
  3. If the circle is on the red layer and the state is active we set the temp variable to true.
  4. Update the text based on the temp variable.

You could even make the temp variable a value instead of a boolean to count how many are left.

Easy Upload (.json file 30 day expiry)
Pastebin (no expiry)

Thanks for the assistance @Eiklahc. Your idea of using a boolean to check whether there are any objects I don’t want helped me come up with this solution:

1 Like