Pause doesn't work

I created this code for pausing my game

When:System/listener/key down/A
And:Border square/counter=0
Do:Border square/counter/set value=1

When:System/listener/key down/A
And:Border square/counter=1
Do:Border square/counter/set value=0

But it doesn’t work at all. I press “A” the value is still 0. Why is that?

4 Likes

Hi @Thebeast ! Welcome to the our Forum! :mechanical_arm:
This is because two events are checked in one time (The events go in order, when you clicked the button, all events are checked one by one, and only after that the action is considered completed.). Try using a timer as a delay, for example:

When :counter=0
Timer/Timer Label/Reset Timer

When:System/listener/key down/A
And:Border square/counter=0
And:Timer/Timer Label<1

Do:Border square/counter/set value=1

When:System/listener/key down/A
And:Border square/counter=1
And:Timer/Timer Label>1

Do:Border square/counter/set value=0

3 Likes

Thank you so much ready.

4 Likes

Hi @Thebeast and welcome to the forum. You can also try the following method. That is what I try in similar situations:

STEP 1: Set the counter value of Bordered Square to 0

STEP 2: WHEN: System > Listener > Key Down > A
DO: Bordered Square > Counter > Add > 1

STEP 3: WHEN: Bordered Square > Counter > Greater Than > 1
DO: Bordered Square > Counter > Set Value > 0

4 Likes

In this way, the counter value would increase by 1 whenever “A” is pressed, like 0, 1, 2, 3, …
But since we have made sure that whenever counter > 1, counter would reset to 0. So it would be like:

If counter = 0 and “A” is pressed, counter turns 1
If counter = 1 and “A” is pressed, counter turns back to 0

5 Likes