How do I tell an event to check if enemies are all dead inside a room to open a door?

Hello again,

So I want the event manager to scan a room if there are enemies inside it, if there are no enemies left alive, then the door opens.
If I just use individual enemies then that would be tiresome, I want it to be able to scan in a group object, and I want this event to happen for every room the player goes into.

1 Like

Object and groups have 2 conditions that count objects. You can count the number on the scene or filter the list using a condition and count how many are “picked”. This could be useful if you want the number of a certain type. You can use any condition(s) before the count. They can also be used as expressions.

image

.

Hey!

Can you explain further about how it scans only a room for enemies?
Because from what I’m understanding “Number of object instances on the scene” refers to the objects I assigned in the entire scene and not inside a single room.

How are you telling rooms apart? Are you using separate scenes or a background object?

If you use a hidden background sprite then you can check if any enemies are in collision with the background object or you could compare their x and y. You wouldn’t need to count them. I’m not sure why I recommend the count condition. You can just as easily use a collision inside a not.

test it. The black boxes are draggable

Edit: IDKW I recommend the count condition, that would be redundant if you’re already using another condition. You need the NOT condition though and not an inverted.

1 Like

I haven’t tried out your suggestion yet as I’ve been testing out some stuff
This purple rectangle is supposed to reprsesent a room and it’s supposed to scan if there’s any enemies inside it.
If there are 0 enemies inside it a yellwo ball will spawn on the player’s location.



But here’s my problem, it wont spawn a yellow ball on the player if I destroy either 1 of the enemies inside the rectangle, I have to kill both.

Are there more enemies on the scene but in different rooms? If there are then you can use my example and check if collisions don’t exist. A regular invert collision would just be asking "are there objects not in collision with the box. The not inverts the result. So, if there are collisions it would normally trigger but the not inverts it. If there aren’t collision it would normally not trigger anything but the not inverts it and triggers the action(s).

Ok so I’ve tried this and it works!
But the problem here now is that the yellow ball that spawns on the player only happens once, if I kill an enemy on room 1, the ball spawns, but if I kill the enemy on room 2 it doesn’t spawn

image

You need to specify the current room either through an id or another collision test like player is in collision with room. Checking the id or name of the room would use fewer resources. Probably the same for the enemies. Or maybe [not] point is inside.

Either way, you need to pick the room first and then compare the enemies in collision with that particular room. Conditions are like filters. You start with all rhe rooms and use a condition to pick one and then you compare that one room with the enemies.

Player is in collision with room (picks 1 room)
[Not] Enemy is in collision with room

I’m not at my PC. I’d like to do some testing. I don’t like changing recommendations but we’re all doing the best we can. Trying to think of the best way to do stuff. The first idea isn’t always the best. It’s often the easiest to implement and explain. But the easiest way it’s always the most efficient. We need to take into account what Gdevelop does in the background but that requires a deeper understanding of Gdevelop and like you, I’m still learning.

When I’m at my PC I can throw together some examples if needed.

Either by collision, point is inside or compare the x,y to the room bounding box. There are so many ways. It’s tough to choose since it varies from project to project.

I think point is inside would be just a efficient. Also, since you have a rectangular hitbox, eirher way. It won’t be too demanding. It would be different if you had a more intricate shaped room.

I feel like I’m babbling but I prefer to explain my decision instead of just providing the solution.

Update! it seems that what I had to do was also add if the player is in collision with the enemyChecker which is the room.
So now I think it’s working exactly as I want it, it’s now spawning the yellow ball in every room when it is cleared of enemies.

I’m still open to other suggestions

1 Like

If it works, I say use it. If the hitbox is rectangular and there’s not an enormous number of objects then other methods wouldn’t be much different.

Deciding what is most efficient sometimes takes a deeper knowledge of how things work behind the scene plus trial and error. It’s really not as important with fewer objects but very noticeable with a lot if objects.

I’m not the person to ask on that level. I know the language but execution is a different story.

Fewer events aren’t always better because it depends on what Gdevelop does in the background. It can read fewer lines but take longer to do each one. It depends on the method. All events aren’t created equally especially when multipled by frame rate and time.