How do I check for player button input?

  • Ok so I searched around and i couldn't find anything on this but i was curious if anyone can tell me how I can figure out if a player has pushed a certain button? For example... I want the player to push A rapidly, the left button, B button or X button. I'm just not sure how to check for that and see if the player has done it correctly then do what action I want and if not have a penalty or do a different action. Any help on this would be greatly appreciated, thanks!!!

  • You add the keyboard object and use 'On key pressed', does that resolve it or were you wanting something else?

  • No! LOL I wanna check and see if player pushes the correct button. For example... I want the player to push the A button but how do I know if they pushed the A button and not the B button? But I also want them to repeatedly push a certain button at times also but again... how do I check to make sure they are pushing the correct button and not just something random. Hope that makes more sense

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Well technically you do still use 'on key pressed' to determine if it was pressed, because something will action if that key was pressed meaning it's true. There are loads of approaches. You could do it with 2 variables, one which changes whenever you press a key so on A pressed, set it to A. You check this against another variable which is the "correct key", so if the correct key variable is "A" and you press the A key then both of those variables would be the same and feedback you pressed the right one.

    As for spamming again you could use those 2 variables in a different way. Set the "correct key" to be spammed to "A" and ensure this time that it always matches the other variable when a key is pressed. If it differs then they pressed another key.

  • "On key pressed" and select which key.

    Or you can use "On any key pressed" and compare Keyboard.StringFromKeyCode(Keyboard.LastKeyCode)

  • Well technically you do still use 'on key pressed' to determine if it was pressed, because something will action if that key was pressed meaning it's true. There are loads of approaches. You could do it with 2 variables, one which changes whenever you press a key so on A pressed, set it to A. You check this against another variable which is the "correct key", so if the correct key variable is "A" and you press the A key then both of those variables would be the same and feedback you pressed the right one.

    As for spamming again you could use those 2 variables in a different way. Set the "correct key" to be spammed to "A" and ensure this time that it always matches the other variable when a key is pressed. If it differs then they pressed another key.

    ahh... ok! Yeah i'll have to try that out, thanks a lot!

  • "On key pressed" and select which key.

    Or you can use "On any key pressed" and compare Keyboard.StringFromKeyCode(Keyboard.LastKeyCode)

    ok, i'll try this as well and see which works best, thanks!

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