[Solved] Different actions with same condition with keyboard press

Hello all, I wanted to make a story game for my students with the following flow: hide the rectangle when I press Num1, and show it when I press Num1 again. I tried to set an intermediate to avoid crash of the conditions, e.g. change of variables and set one more conditions to trigger the action.

However, the problem was that nothing happened when I pressed Num1. Since there are other actions with pressing other numbers, I don’t prefer the flow of “Press 1>Hide, Press 2>Show” though it works. Could you all help to look at the flow picture to see if there are some problems? Thanks!

2 Likes

What you have to do is replace “Num1 key is pressed” to “Num1 key is released” (Search key released in the function menu). Then, it will work with both the way you did

1 Like

Hi Midhil, thanks for your reply, I tried to set it but it does not work as nothing happened as I pressed Num1. Thanks!

Hi, sad to hear that iot did not work. But, I found a thread that will solve your problem
: Togglable Door?

1 Like

You need to change the events structure

Like
Conditions:
If Num1 Key Pressed or Released
Trigger Once
Action:
Change variable Picture -=1

Then in two separated events
Event1:
Condition:
The variable Picture1 = 1
Action:
Hide YellowBackground

Event2:
The variable Picture1 = 0
Action:
Show YellowBackground

2 Likes

this is how its supposed to look like

both, beginning of the scene and key released don’t need a trigger once, since there trigger once by nature.

2 Likes

Thank you @Slash, @UlisesFreitas and @Midhil for your suggestions! I followed Slash’s picture flow and it worked! You all are really great and helpful!

Though it works, I do not know the logic behind the sub-condition structure and why the initial setting did not work. I tried to translate the flow into words to see if it’s correct(is the testing works sequentially or at the same time?):

when Num1 is released>
check if the Picture1 variable is 1, it yes>Hide YellowBackground and change the variables Pic to 0 and toogle to 1
change the toogle variable to 0.
check if the variables Pic is 0 and toogle is 0, if yes>Show YellowBackground

BTW, thank you all as I have tried for several hours.

1 Like

you use subevents, to have all events below the main events be triggered.
they are triggered in order.
main event key is released triggers 1 to 3 in order:
1: if pic1 = 1 do actions
2: if toggle = 0 & pic1=0 do actions
3: set toggle to 0

notes:
in subevent 1 we change toggle to 1 to make sure event 2 is not triggered. event 3 will still fire.
if event 1 is not triggered, event 2 will trigger, because toggle is still 0.

the condition, if picture1 = 0 is actually not needed, if you have only 2 states of this variable, since it can only be 0, if event 1 was not fired.

The events you tried before go like this:
key press:
check if var pic1=1 action set pic1 to 0
after this check, you have the next check
if var pic1=0 action set var pic1 to 1
this means, the second condition will always be true, because the event triggered before will set the condition. Thats the reason you need to have some seconday check (variable(toggle)) to make sure, only one of the events will trigger.

2 Likes

Understood and new logic unblocked. Million thanks!

2 Likes