Using the same key to toggle a state.

Get help using Construct 2

Post » Fri Nov 04, 2011 10:33 am

Hello all,

Im trying to get my each around this event based programming and I can't seem to solve this problem of using the same keyboard button to toggle a state on or off.

Attached is my implementation:
http://dl.dropbox.com/u/5760424/lol.capx

What it is suppose to do:
When the black square moves (using the w,a,s,d keys) to a grey square and presses the space button (while facing the square) a message pops up and the black sprite is frozen until the interaction message is terminated with the space button again. However I am unable to terminate the interaction message with the space button and I am temporary using the control button to terminate the interaction message. This is because the space triggers both popup and termination of the message at the same time. This is where I need help. If you don't get what I mean please download the file from the dropbox link.
B
2
G
1
Posts: 5
Reputation: 460

Post » Fri Nov 04, 2011 11:07 am

Use the boolean instance variable that you've already set up for the player: 'interact1'

keyboard 'space' - toggle boolean 'interact1'
- player boolean 'interact1' true? - do stuff
- player boolean 'interact1' false? - do other stuff
or something like that.

Although, I haven't gone through your example very closely... as long as you only toggle it once per tick, you shouldn't have any problems.

edit: Here you go.plauk2011-11-04 11:21:10
B
28
S
7
G
7
Posts: 102
Reputation: 6,483

Post » Fri Nov 04, 2011 11:23 am

Toggle? Simple:

+ On some key pressed
- somevariable = 1 - variable
B
62
S
21
G
12
Posts: 1,910
Reputation: 13,155

Post » Sat Nov 05, 2011 10:23 am

Thanks, I'm so blind I completely missed the 'toggle' action. This is exactly what I was looking for.
B
2
G
1
Posts: 5
Reputation: 460


Return to How do I....?

Who is online

Users browsing this forum: Megavolt and 0 guests