|
Hg Beeks
llGetElement(80);
Join date: 13 Apr 2006
Posts: 134
|
07-02-2007 05:00
I've got a script that seems to successfully respond to keys being pressed down, and sends the messages I want it to. However, every combination of change I can think of will not work for change on being released. I need a series of if/if elses that will check for what button is being released - How would I do that? The closest I have now is a series of ifs that check, but only go off if the first is true.
|
|
Domino Marama
Domino Designs
Join date: 22 Sep 2006
Posts: 1,126
|
07-02-2007 05:47
control(key id, integer held, integer change) held & change = key press held & ! change = key held ! held & change = release I tend to just check held and set my own flag, code is easier to read and gives a consistant amount of checks per event.. also means that other events can just check the flags I've set if they need to know the current keystates. if ( held & CONTROL_FWD ) { if ( ! forward ) { //key press stuff here forward = TRUE; } // key held stuff here ( can put in else clause if not to be run on intial press ) } else if ( forward ) { // key release stuff here forward = FALSE; }
|
|
Hg Beeks
llGetElement(80);
Join date: 13 Apr 2006
Posts: 134
|
07-02-2007 13:12
Is there any chance you could elaborate on that? What I'm reading from it doesn't seem to help explain why I would only get the forward direction when I release a key. And it looks like the code you've written only works if forward is being held down, and even then the code you have looks like it would cause the script to automatically flip "forward" from true to false and back constantly while the button is held down.
|
|
Qie Niangao
Coin-operated
Join date: 24 May 2006
Posts: 7,138
|
07-02-2007 13:55
As I read it (I had to press "Quote" to get it formatted to see) the code is correctly detecting leading and trailing edges of CONTROL_FWD using the "forward" variable. The test "else if ( forward )" only executes when CONTROL_FWD is not held--detecting that trailing edge (where one would do the "key release stuff"  . There are the noted advantages of this global flag approach compared to an explicit test for "!held & change", but it does use an extra variable this way. But in any case, if there's really never a "!held & change" event generated--haven't tested that myself--that would warrant a jira.
|
|
Domino Marama
Domino Designs
Join date: 22 Sep 2006
Posts: 1,126
|
07-02-2007 15:37
Qie basically has it. This is just a one key example, you would need to do similar for each key you want to handle. I prefer this to more conventional approaches as there's only two checks per pass for each key you are interested in. The first check is always done, then only one of the other checks depending on result.
"if ( held & CONTROL_FWD )" checks whether the key is currently held or not. If it is then check whether the script already knows it is held with "if (! forward) ". If the key is not held then it checks if the script thinks it is held with "else if ( forward )", so "forward" is set to TRUE on the key press and FALSE on release. It won't change at all while the key is held.
once you've done this for all the keys, you can check for combo's with things like:
if ( forward & right )
|