How do I check against all keycodes inside a family?

Get help using Construct 2

Post » Sun Jan 22, 2017 8:23 am

I have a family of 8 players, each using one key for the game. There's a family variable keycode, and I save the keycode on it.

However, I want to issue actions for the keycode is_down/release, and I'm wondering if I can do it with the family (instead of making 8 repeated actions for all the players).

I did this to allow for the down to be detected, and it appears to work fine:
>keyboard: on any key pressed
>>keyboard: keycode keyboard.lastkeycode is down
>>>system: pick players by evaluating players.keycode = keyboard.lastkeycode

Then performing the required actions (I would get to them with "keyboard: keycode player1.keycode is down" if I wasn't doing this, but would have to repeat for all the players.

Is there a way to detect the release of the key with the family?
Also, am I doing it right for the down event or is there a better way?

Thank you very much in advance!
B
22
S
4
G
6
Posts: 60
Reputation: 4,507

Post » Mon Jan 23, 2017 1:30 pm

For bound keys with 'Key released' functionality, I used two dictionaries. The dictionaries stored which key was down each tick by recording its keycode (you can also store the player ID in the value to simplify other code I would have thought). At the end of each tick the game loop would evaluate which dictionary keys were present this tick, and compare it to the keys present in the previous tick.

If the key is now present, but was previously absent, call a function that corresponds to 'Key pressed'
If the key is present in both, call a function that corresponds to 'Key down'
If the key was present in the previous tick, and absent in the current tick, call ... 'Key released'!
The LEVEL GENERATOR TOOLKIT



24 functions dedicated to producing randomly generated terrain for all kinds of games.
B
25
S
7
Posts: 242
Reputation: 2,306


Return to How do I....?

Who is online

Users browsing this forum: Artcadev, brunopalermo, ST314 and 23 guests