Having trouble detecting Key Presses

  • 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:

    <img src="http://i.imgur.com/0dK4Ody.png1" border="0" />

    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.

  • 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.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)