One key

This forum is currently in read-only mode.
From the Asset Store
Piano Tiles with Sound Keys - I don't have 50 words to type here
  • I'd need to prevent a player from pressing more than one key at the moment. Now I have it like this

    On key Up arrow pressed - do something

    [negated] Key Down arrow is down

    [negated] Key Left arrow is down

    [negated] Key Right arrow is down

    On key Up arrow pressed - do something

    [negated] Key Up arrow is down

    [negated] Key Left arrow is down

    .....

    etc.

    and that means + 3 lines of code for each key. Is there a simpler way? I've tried to use

    On key Up arrow pressed - do something

    [negated] Player 1 "Down arrow, Left arrow, Right arrow" is down

    but this didn't work

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • you could make variables that keep track of certain key combinations (upLeftRight,leftUp etc.) that are set to 1 when combinations of keys are held down. Then just check if the variables are equal to one instead of checking the keys. Every frame, you should set the variables to zero before the events which set them to one, and the events which check if they're equal to 1 should come after both the flush (setting them to 0), and the set (setting them to 1 if the keys are down).

    In the case where it's many different sets of keys that are being held down for every event, you'll just have to make a lot of events. Variables might not be worth it, unless you have lots of events which check key combinations. If you want, you could nest them in a subevent and then collapse it to make it look neater.

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