# How do I make this simple thing work?

Get help using Construct 2

### » Wed Feb 11, 2015 9:22 am

When I press 'G', the NumberTest instance variable is always set to 0. I understand it reads from top to bottom, so how do I get this thing to work? Supposed to happen is: Press 'G', set NumberTest to 1, when pressed 'G' again, set NumberTest to 0.

B
7
Posts: 23
Reputation: 321

### » Wed Feb 11, 2015 9:26 am

Use 'Else' statement for testing

NumberTest==0
else NumberTest==1
B
23
S
4
G
2
Posts: 364
Reputation: 2,392

### » Wed Feb 11, 2015 9:28 am

Follow it through in your head. When G is pressed, and NumberTest is 0, it will be set to 1. On the very next line it says, if NumberTest is 1 (which it is because you just set it) then set it to 0. So almost immediately you've set it to 1, then back to 0 again. You probably want to have 2 'On G pressed' events, one for each of those lines.

A nicer way would be to do

On G pressed
Sprite | Set NumberTest to 1 - Sprite.NumberTest

edit: otherwise else as suggested above. Lots of choices
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

### » Wed Feb 11, 2015 9:30 am

try with 1- sprite.numbertest
B
82
S
24
G
69
Posts: 1,362
Reputation: 44,214

### » Wed Feb 11, 2015 11:24 am

I guess the 'else' method is the natural way, but the subtracting trick is awesome to know. Thank you all.
B
7
Posts: 23
Reputation: 321

### » Wed Feb 11, 2015 11:55 am

Could also use a Boolean and just toggle it
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596