Get the invert of 'On keyboard key pressed'?

0 favourites
  • 4 posts
From the Asset Store
Random Maze Generator with Door & Key System - tutorial capx
  • Hello! I didn't know how to formulate my question better.

    I'm doing a one-button rhythm game; you have to press the 'Space' keyboard key on the correct beats. For example, a music is playing, and you have to press Space at specific beats, like the 4th, the 13th, the 20th, and so on.

    Currently I know when the beat to tap is there and when it's not; and it's stocked in a boolean 'beatToTap'.

    When this boolean is true, and Space is pressed, you got the beat. My issue comes when the boolean is true but you didn't tap the Space button. I fail to find a good way to detect the missed beat.

    How can I detect that? I tried to invert 'key down' but it doesn't work, without much surprise, as I need the precision of on key pressed rather than just using a key down check.

    I also tried the following, which works, but I'm afraid it's not the best way to do it:

    > On Space Pressed: (btnTap=false) {btnTap = true}

    > if (btnTap=true){Wait 0.1 sec; btnTap=false}

    Thanks a lot for your help, I hope I made my problem clear!

  • Instead of relying on a superhuman skill of pressing the button at the exact tick/frame the beat happens, you could have the "on button pressed" trigger inside a group. You must activate and deactivate that group in a way that the player has a window of at least 0.1 seconds to have the correct timing.

    So...

    Beat is about to happen:

    activate group

    (Group contains "on space pressed" event)

    after 0.1 seconds deactivate that group no matter what.

    If succesfull press, then yey

    else

    ney.

    Edit... oh it didn't show me the image when I read your post.

  • I'd suggest having another boolean that says: "wasTapped".

    If you receive a tap (when beatToTap is also True), set wasTapped to True. (otherwise it will remain False)

    At the end of each beat, check* if wasTapped is True, if it was, then good, make it false for the next beat, AND if it remained False, you've missed the beat.

    *You can use a Function to 'checkTapped' (or just a sub-event after the time-delay, depending on how you've programmed the timing)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I would do it like this:

    After the 0.1 s beat has ended, take away one point from the score.

    On space pressed

    -if beatToTap is true, then give two points resulting in a +1 score.

    -else, then take away one point resulting in -2 points in total.

    But to remove cheating (pressing space many times during this 0.1 window), you would need to deactivate the space pressing group to not count multiple hits. Or simply set beatToTap to false after the first succesfull press.

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