How works a easy for each


#1

I’ve never used “for each”, now I have 3 instances of an enemy, if I touch one, I want to hide all 3.
1
Isn’t it how it works and in this case I have to work around with an object varibale?
The for each examples work differently and have more objects…


#2

1, you don’t use the for each object event well in this situation.
2, it can be done with “for each” but in my opinion you aren’t need that for this task (if you aren’t want to do other thing with your instances, just hide). just use the “pick all instances” condition.


#3

You could use groups to do that easily too… put all your objects in to a group object, then hide the group when the player is in collision… http://wiki.compilgames.net/doku.php/gdevelop5/objects/base_object#object_groups


#4

Sounds good, but unfortunately only the touched enemy is hidden.

I think this is for several objects with only one instance.
If there are multiple instances, it won’t work for everyone.

My idea with the variable doesn’t work either, “repeat” 3 times also not.


#5

It works for all instances of the object n my side


#6

Here’s a quick example https://srv-file18.gofile.io/download/UZ839D/Hide%20All.zip


#7

than you don’t use it well too.

by the way, lets do it with the for each as you want.
you has to create one main event with the mouse touch condition, and no action. than add a sub-event for this. that will be the “for each”. don’t use condition in this, only the event: hide.
the same the situation with the “pick all instances” condition. you has to put it in a sub-event.


#8

Okay thanks, pick all instances in a sub-event works.
For each and group not, but I’ll test it tomorrowin a new project to understand.


#9

To go back to the original problem, the for each does its actuíons and conditions once and only affect one object. That means that it would hide all enemies if you just had the action, but it will also do the check for each object and you don’t want that. You want to use the condition in a normal event (you don’t care which object has been touched) and then make as subevent a for each event that will hide all enemies.


#10

2


#11

thanks, but yes it only works for you bc you are using a second object.