One key

For questions about using Classic.

Post » Fri Nov 12, 2010 2:46 pm

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

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
Posts: 774
Reputation: 6,685

Post » Fri Nov 12, 2010 4:20 pm

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.
Posts: 1,224
Reputation: 8,424

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 8 guests