How exactly does "Trigger once while true" work?


I was toying around, making a puzzle platformer game, when I decided to try adding weapons. The code was simple:
Trigger once while true
Left mouse button is pressed down: Spawn bullet at position “player”

The code seemed fine, but as I tested it, it just didn’t work. I was racking my brain for some 15 minutes when by sheer accident I flipped the two conditions so it said:
Left mouse button is pressed down
Trigger once while true: Spawn bullet at position “player”

And suddenly, it worked! So… why? Why didn’t the first one work? I’ve looked it up in the docs and on google, but I couldn’t find anything about how the condition actually works. Why does its position matter? And can someone update the docs about its correct usage then?

Yes, order matters in GDevelop.
The events sheet is read by the software 60 times per second, from top to bottom, block by block, line by line. I believe this is stated somewhere in the intro pages of the wiki.

The first time Trigger once is checked, it allows GDevelop to pursue (= keep reading the next conditions of the same block). It will then prevent further reading until all conditions above it in the same block are false.

If you put it on top, it can never be false (“once while true”), hence you’ll always see it at the bottom.

1 Like

The trigger once doesn’t trigger once while the other conditions of the event is true, but trigger once while previous conditions (including parent events) are true.

It works the following way: when it is called, it sets an internal variable “wasExecuted” to true, and returns the inversed value of wasExecutedPreviousFrame. And after each frame, it sets wasExecutedPreviousFrame to the value of wasExecuted then sets wasExecuted to false.

This works because GDevelop doesn’t call next conditions when a previous one was false (after all there is no point as all need to be true to execute actions).