[Solved] State toggle loop?

I want to make the UI to show and Hide when I press Tab.

But what’s happening is:

Condition:
Tab key released
The scene variable UI = 0

Action:
Show Layer UI

Condition:
Tab key released
The scene variable UI = 1

Action:
Hide Layer UI

But these events both active as soos as the variable changes state. Thus creating a loop that in the end, does nothing.

I know there’s a way to go about this by adding in a another variable that acts as a barrie for this, but I can’t seem to figure it out. Pls help.
Ty

Create a new scene variable and named it: GoInto

_condition (level 1): key released → action GoInto = FALSE
.L subcondition ( level 2): UI = 0 → action: UI = 1 and GoInto = TRUE.
.L subcondition ( level 2): UI = 1 and GoInto = FALSE → action: UI = 0

It’s the GDevelop ELSE command workaround

1 Like

Or you could just use the toggle Boolean for a Global, Scene or Object Variable.

As @jumpingj says you can do something like this.

1 Like

Yeah @jumpingj is right
You need a condition to check if the scene variable is on or off

You can find a full guide about that topic there:
http://wiki.compilgames.net/doku.php/gdevelop5/tutorials/how-to-make-togglable-states-with-variables#how_to_toggle_states_using_variables

2 Likes

Ty you so much you guyz :+1: