Scripts / g-keyPressE Question

Author
Message
Saintyboy
9
Years of Service
User Offline
Joined: 18th Jun 2015
Playing:
Posted: 11th Jul 2015 02:00
I see that the only key you can assign to this function is E.
So I have a chest and I have a key within the chest - player doesn't get to see the key or indeed pick it up until chest lid is open - all fine to here.
However, its the same key press to open the chest as it is to pick the key up and so if the player holds down the E key for more than a nano-second the function fires twice simultaneously opening the chest and taking the key so the player sees nothing. I want the player to have to pick up the key and get tpo read the text once chest is opened.

Any advice on a workaround for this from anyone?
!nullptr
Forum Support
9
Years of Service
User Offline
Joined: 27th Mar 2015
Location: Australia
Posted: 11th Jul 2015 02:30 Edited at: 11th Jul 2015 02:37
When using keypress you need to

1) stop the code executing once it's done (using pressed=1) and
2) check for keyup. If it is, reset pressed to 0 for next time a key is pressed.

Here's an example. If you step through it you'll see that once "e" is tapped, pressed becomes "1" and the code cannot execute again until the "e" is lifted and pressed is reset. Because "pressed == 0 " is false the call to execute is prevented. When pressed is 0 and "e" is not pressed the code cannot execute either.



It's a good idea to include your script (use code tags) when you have problems and then we can often make the correction in your own code so you can C&P it back.
AKA SisterMatic (Steam)
Development/ Gaming Rigs
Sys 1: i7-4770 (3.5)/16Gb/128 SSD/3Tb/970gtx/2 x 23, 1 x 27 LCD - Sys 2: i7/8Gb/670gtx/1.5Tb/1 x 23 LCD - Sys 3: Amd Quad/8Gb/645gtx/1Tb/30" LCD
PM
Saintyboy
9
Years of Service
User Offline
Joined: 18th Jun 2015
Playing:
Posted: 12th Jul 2015 01:08
Inullptr - thanks for the prompt reply, and I understand your principle but is if GetInKey() == ""
your key up check?
I am using g_KeyPressE
Ian
!nullptr
Forum Support
9
Years of Service
User Offline
Joined: 27th Mar 2015
Location: Australia
Posted: 12th Jul 2015 01:49
I wrote that snippet for GetInKey() because you can use it for all keys, not just E and it does the same thing anyway. Allows you to reuse the same code in other script.

GetInKey() == "e" is the same as g_KeyPressE == 1
GetInKey() ~= "e" or GetInKey() == "" (or anything other than "e") is the same as g_KeyPressE == 0

If you prefer to use g_KeyPressE then use that instead.
AKA SisterMatic (Steam)
Development/ Gaming Rigs
Sys 1: i7-4770 (3.5)/16Gb/128 SSD/3Tb/970gtx/2 x 23, 1 x 27 LCD - Sys 2: i7/8Gb/670gtx/1.5Tb/1 x 23 LCD - Sys 3: Amd Quad/8Gb/645gtx/1Tb/30" LCD
PM

Login to post a reply

Server time is: 2024-12-21 18:56:39
Your offset time is: 2024-12-21 18:56:39