0
Answered

Flip/toggle states with same key

Living Ghost 7 months ago in Game Creator updated by Marti (Lead Developer) 6 months ago 5

Hi,

I'm sure this has an obvious fix. However, while I understand how to change states with key down/up triggers, I can't find out how to make the states be activated and deactivated with the same key. For instance, want to make the player crouch by pressing C once, and then reset the state when pressing C again. 

What's the best way to go about this? Thanks!

Unity version:
Game Creator version:
+1

Something like this...


Create a Variable/Bool and name it something 

Set a trigger for Input/onKeyDown/C

Add an Action to this trigger and add Variables/Variable Bool Toggle and select the variable above.

Now when you hit C it will be true, then hit C again and it will be false.

Now create another Trigger for on Variable Change and select the above variable 

Add a condition, if variable true, do Action (change state or what ever) and if false, do other Action (change state back of whatever).

There are other ways of doing it, but this works and is Simple.

Example Inventory key press i open and close

Make a trigger on key down key is i

and then in this trigger create a condition with some actions

1.Make a local bool variable and call it boolToggle

2. Create a condition if bool variable false

then create an action Inventory Ui open and another action Toggle bool variable your local boolTogglei that what you set earlier. 

Then in Else if bool variable true, create action Inventory UI close and another action Toggle Bool variable

you use your local boolToggle variable for this. 

which solution did you use? Toggle Bool or  on Variable Changed