[Solved] Trigger once (and for all!)

I’ve seen conflicting things about trigger once over the couple of years I’ve been using GDevelop, and I think many users don’t quite understand it. I’m still not sure I’m using it optimally.

Some say to always put it under all of the conditions in an event. If that is the case, why does GDevelop let the user position TO where they like?

Some suggest that TO can optimise your game and prevent conditions under it being read unless conditions above it are true. Sort of like a gate, reducing the amount of conditions GDevelop needs to check. I have also read posts that say GDevelop reads all conditions in an event regardless of trigger once position. Which is true?

If I have a button press condition followed by a trigger once, and under that are various other checks, is that more optimal than having the TO under all conditions? Do conditions under a TO fire for one frame or more than one? Please no speculative replies. I’d love to know for sure how this works. Thank you.

Edit: I have of course designed events with Trigger once in various positions, as a way of experimenting, and I use it in the order of my conditions in ways that seem best and work well in my game. The purpose of this post is to get clarity on how TO works, as I have not been able to do that from reading the Wiki, and other learning. That may well be a failing on my part, but I don’t need that, or any other perceived failings, pointed out. Many thanks.

2 Likes

We have OR and NOT (if one of these conditions is true and if all of these conditions are true)
That alone is reason to being able to move it
Not to mention you can move it from one event to another
Other is UI design
You do not want to create one special object in UI that would be handled different than others
(Where when pasting some conditions it does going automatically to bottom)
Think of it as having 20 enemies in your game
And all of them use same exact logic
Now imagine you need to do separate logic for just one of them
Now imagine you have 200 enemies
Imagine you already have few enemies for which you need to create separate logic
You want go into repetition as much as you can without creating new logic for individual enemies
And same goes UI wise
As for UI now throw mobile app into the mix

And you are couple years here and you did not think to test it if you don’t want speculations?
I mean in regards how exactly trigger once NOT on bottom works?

It would be as simple as having 2 conditions and placing trigger once between them and making both true

And add in action play sound and you would have your answer very quickly

Where everything in event needs to be reed (in regards to conditions)
Cause how otherwise it would know each condition there is true or false?

Even if trigger once would affect only conditions above it inside event
Then still conditions under it could change while ones above it could remain true
So all would need to be checked anyway

1 Like

Does this discussion from a while back that explains how they work help with understanding how Trigger Once works?

2 Likes

Edit: it’s a bit over my head, but thank you for the link. I’ll keep bashing away until I get a firmer grip on it. I guess the important thing is that I seem to be using it correctly and my game is working as intended. I’ll mark this ‘solved’. Though I am none the wiser, :upside_down_face: the replies here may help other users.

Let me add my 2 cents.

The placement of trigger once is more about strategy than efficiency. Although, there might be some benefit just like splitting conditions between subevents might create a slight benefit. Personally, a lot of it is more visual. It’s a way to breakdown events visually into easier to understand chunks. The event sheet is different than the final code.

Let’s look at the following
Mouse is pressed
Space is pressed
Trigger once

The trigger once is at the bottom so it applies to all of the conditions. The only thing is if you held the mouse then you could repeatedly tap the space and it would keep being triggered. Every time either condition goes from true to false the trigger once is removed and it’s ready to be triggered again when all of the conditions are true.

Now, if you move the trigger once up a spot
Mouse is pressed
Trigger once
Space is pressed

Now, if you press the mouse and the space at the same time it will trigger but if you press the mouse and repeatedly tap the space button nothing will happen. It’s only going to test the conditions before the trigger once. In fact, if the space isn’t pressed either before or at the same exact frame when the mouse is pressed then the actions will not be trigger while you press the mouse. It would only give you 1 chance per press until the mouse was released.

So, yes. It might be slightly more efficient but it also changes the process. It’s just as efficient to arrange the conditions starting with the least likely to happen and the conditions that require the least amount of time to evaluate.

Imagine if you wanted to make stew. Which ingredient would you check first? Would you check for salt and pepper before beef or would you check for the beef first? If there’s no beef then it doesn’t matter if you have salt. You almost always have salt.

3 Likes

Check for beef? I’m more of a red lentil and smoked paprika type of person :grin:

Something clicked in my brain when I read your reply, and that was the sound I was hoping for! The click of clarity! Thank you.

1 Like

Great topic and replies! I often just do stuff that seems to work without bothering to find out if it was necessary, correct, or even advisable.

1 Like