Button perform 2 actions (Solved)

For example. I have an NPC set to follow the player automatically. I want to add a feature to make the NPC stop following if “d” is pressed then start again if “d” is pressed again.

Something like:

if “d” is released and NPCFollow = 0
Set NPCFollow = 1

if “d” is released and NPCFollow = 1
Set NPCFollow = 0

You’d think that would work, but for some reason it doesn’t. I even added a test object so that when NPCFollow = 0, the tester object hides and vice versa, but the tester object never hides.

What exactly is the problem here? I’m confused.

What i do to simulate a toggle is to set a scene variable then in some event when XX key pressed or released change that var and check its value, for instance to show/hide hud i do this.
Note: The trigger Once

What does it mean at the top where it says " = 1 - Variable(gs_hide_show_debug)"?

Is it subtracting the hid_show_debug variable by itself? My line like that just ends with the 1

You must create this variable at begin of the scene and set to 0
Begin of the scene
gs_hide_show_debug = 0

Then when the key press or key release event occur is going to do math
1-0 = 1
1-1 = 0
That is how it wworks

This is what I did. I’m pretty sure I follows your steps, but it’s still not working. It won’t even show and hide the tester object. I can’t figure out what I missed.

(Sorry, should’ve posted the image sooner.)

IU think when you key press you are refering to Varible instead of GlobalVariable maybe is that.
It must be like
Change the global variable AnyaFollowVar set to 1-GlobalVariable(AnyaFollowVar)

1 Like

Aha! Thanks so much! I didn’t know I had to specify the difference. It’s working perfectly now.