Having trouble detecting Key Presses

Get help using Construct 2

Post » Sun Jul 28, 2013 5:39 pm

Hey I'm trying to make my game so that several different keys/buttons can control the same action, but for some reason when I do this I can't get Key Presses to be detected correctly.

I did this super simple bit of code to experiment:


The outcome of this is that "Score" is set to 100, but not 200.

"KeyPress" never returns true outside of that, but "KeyDown" seems to work just fine.
Dexiro2013-07-28 17:42:06
B
3
Posts: 2
Reputation: 229

Post » Sun Jul 28, 2013 6:00 pm

Any 'On' condition (with the green arrow next to it) is a trigger. Triggers are called whenever the event occurs OUTSIDE of the regular script loop, so you can't place any code after them expecting that code to be called next, it won't be.

So what is happening here is the key is pressed, the JumpKeyPress is set to true and the Score set to 100, then the code returns. It does not keep going. So the next time the script runs, your Every tick event sets JumpKeyPress to false, and the Is JumpKeyPress won't be evaluated.

What you could do here is not reset every tick, but have the Is JumpKeyPress reset the value.

KeyDown works because it is a regular event, not a trigger.
ImageImageImage
B
71
S
21
G
211
Posts: 3,614
Reputation: 119,147

Post » Sun Jul 28, 2013 6:11 pm

Wow awesome response! Knew there was something about Key Presses and such that I wasn't understanding. Should be able to figure it out from here, thanks :D
B
3
Posts: 2
Reputation: 229


Return to How do I....?

Who is online

Users browsing this forum: Aquanex2, Johnzo, Sefardi, tarek2 and 1 guest