"Trigger once" with "Repeat for each instance": different result than expected

Hello, people :slightly_smiling_face:

I have been using Gdevelop for just over 3 months and I don’t know to much about the game engine. But I learned something in that time that is probably one of the few contributions I can give here on the forum. I explains to other beginners that using Trigger once with Repeat for each instance may be being the big problem with their code when they are dealing with multiple instances of the same object. And from what I have noticed during this period has appeared a considerable number of people with this doubt.

They use “Trigger once” with “Repeat for each instance” believing that it will occur one time for each instance, but that is not what happens. The condition occurs only once in a single instance and not in the others instances while the condition is true. I’m not saying it’s wrong but apparently it’s not what many of us expected. We expected that happens once for each instance. I took a few days dealing with my project to understand what was going on and fix the code by removing the trigger once from all events with “repeat for each instance” and “limiting” the events to occur only once using others conditions.

My suggestion is to have some kind of flashy and explanatory warning to prevent users from using “trigger once” with “repeat for each instance” without knowing what will really happen. I do not suggest a change in the effect of the “trigger once” with “repeat with each instance” because I couldn’t even think how complicated that change can be and yours impacts (and maybe someone want to use like it works right now). Also “limit” the “Repeat with each instance” to occurs just one time per instance isn’t a hard thing.

5 Likes

Good call out. Happily, I can say this is currently in progress.

4 Likes

As someone who has ran into this inconsistency before I completely agree Rasterisko!

@Silver-Streak

This Extension is Legendary. It helps so much with lots of instances on screen that you need to repeat a certain variable randomly. Thank you for sharing this really helped my game.

1 Like

Hoping to bring this to the surface again.
I was banging my head in the wall trying to figure out why my enemy particles were not working properly. I discovered that it was the trigger, but couldn’t understand why.
Gdevelop must really include a notice for when you are dealing with this event or at least navigate us to the extension.

when u want something happen 1 time in “a repeat for each event” and for each instances that doesn’t happen just for 1 frame/(step) like particles,anims,ecc… use repeat 1 time instead of trigger once…it will force to cycle between all instances 1 time…this is kind of a trick i learnt messing with my enemies AI

1 Like