Explain the logic please

I know it’s a classic question but explain the logic and the right way to implement. And why it works in this way? Because the variant from the pic doesnt work.I know there’s something about doing every frame + order of events but i don’t understand it.

Hello, guest

About frames and order the wiki says:

Events at the top are executed first. Events are executed every time your game is displayed. This display is called a frame. It executes about 60 times per second.
In 1 frame Gdevelop read all your events from top to the bottom.

In your example when the player released that button it’s true in 1 frame. So, that condition will be true in all events that have it for that frame. Your top (first) event change the scene variable Anim to 1 and the next event (second) change the scene variable Anim to 2. We can conclude that always when the player released the right mouse button the scene variable Anim will be 2 because Gdevelop is reading from top to the bottom.

No doubt there are several ways to solve your problem and what is better depends of your game. I did it:


If your scene variable is less or equal to 2 it will add 1 to your scene variable. In the second event if that variable is bigger than 2 it changes to 1.

About Trigger Once:

The condition “Right mouse button was released” is true only when at the exact moment the player released the button (just 1 frame). Because of that you don’t need the “Trigger once”.

Otherwise, your 2 last events are checking the scene variable Anim. If true always when Gdevelop check it will change your animation of NewSprite2 and you don’t need it, right? So, its a good for performance to put a “Trigger once” in that events.

3 Likes

Thank you! Thanks to your explanation i get it now

GDevelop needs an else condition. It’s a standard part of programming. Yes, there are ways around it, but they are just silly.

Please do not bump posts with unrelated subject matter. Thank you