How do I Toggle global variable value on touch?

Get help using Construct 2

Post » Wed Aug 19, 2015 4:55 am

Hi, I want to toggle speed of object on tapping anywhere on screen. Initially I have global variable "speed" set to 200. I wrote an event like
1. On tap gesture & Speed = 200 --> set speed to 100
2. On tap gesture & Speed = 100 --> set speed to 200
It seemed to do nothing, then I wrote

1. On tap gesture & Speed = 200 --> set speed to 100
2. On tap gesture & Speed = 100 --> set speed to 300
Now on one single tap gesture, the speed is being set to 300.

I wrote the same thing with Keyboard:any key pressed. The same thing is happening. Can anyone explain whats happening here and a work around.
B
8
S
1
Posts: 40
Reputation: 868

Post » Wed Aug 19, 2015 5:13 am

When line 1 runs, you set the variable to 100. Then line 2 runs, the variable is 100, so sets it to the other value. Change your events to check On tap first, then use sub events for the speed decoding using Else on subsequent items so that the variable is only checked once.

On tap gesture
-> Speed=200 --> set speed = 100
-->Else
-->Speed=100 -->set speed = 300
ImageImageImage
B
71
S
22
G
249
Posts: 3,762
Reputation: 138,575

Post » Wed Aug 19, 2015 5:26 am

Thank you, much appreciated. Did the job.
B
8
S
1
Posts: 40
Reputation: 868


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 21 guests