View previous topic :: View next topic |
Author |
Message |
Bagne ALL YOUR NUDIBRANCH ARE BELONG TO GASTROPODA

Joined: 19 Feb 2003 Posts: 518 Location: Halifax
|
Posted: Mon Nov 09, 2009 8:55 am Post subject: keypress issues |
|
|
I have a "swap party" script that is triggered by keypress.
It's strange: if you lean on the designated key (c), "swap" gets triggered multiple times (before the first finishes execution) even though the "permit multiple script triggers" bit is set to OFF.
I've tried implementing a makeshift "suspend keypress" by only allowing scripts to run when a certain TAG (51) is turned on.
This doesn't seem to work - I can't imagine why.
My keypress script looks sort of like this:
Code: |
if (key is pressed(46) ,and, check tag(51)) then( #c
set tag (51,off)
swap # another script
)
set tag (51,on)
|
Am I doing something wrong? _________________ Working on rain and cloud formation |
|
Back to top |
|
 |
TMC On the Verge of Insanity
Joined: 05 Apr 2003 Posts: 3240 Location: Matakana
|
Posted: Mon Nov 09, 2009 12:24 pm Post subject: |
|
|
When a script is triggered, such as an on-keypress, the interpreter checks whether the current script (which, because script are only triggered outside of the interpreter, will always be in the middle of either a wait or one of those very rare commands that cause an invisible wait) is the same as the one that wants to be triggered. If so, "permit multiple script triggers" dictates what will happen. In your case, the current script is swap, and the triggered script is your on-keypress, so the interpreter doesn't see the problem and they pile up.
What you are doing is basically the correct way to prevent double triggering of scripts. However, you should move set tag (51,on) inside the if, otherwise any other keypress will reset the tag! I'm guessing this is your problem, because everything else is right.
You know... you can write key:c instead of 46. I know, I'll remove the table of scancodes from the plotdictionary. _________________ "It is so great it is insanely great." |
|
Back to top |
|
 |
Nepenthe

Joined: 27 Sep 2004 Posts: 132
|
Posted: Mon Nov 09, 2009 12:31 pm Post subject: |
|
|
EDIT: TMC beat me to it (and provided a better answer!)
I think you want to check that tag by itself before you do any keyispressed stuff. This is roughly what my keypress script looks like:
Code: | plotscript, keypress, begin
if(keypressisrunning==false) then( #checks to makes sure a global variable is off
keypressisrunning:=true #sets the global on
if(keyispressed(key:w)) then(#do stuff)
if(keyispressed(key:a)) then(#do other stuff)
if(keyispressed(key:s)) then(#etc)
if(keyispressed(key:d)) then(#etc)
keypressisrunning:=false) #sets the global off again
end |
NOTE: I am using the global variable "keypressisrunning" because I have an inexplicable aversion to tags, but I don't see a reason why a tag wouldn't work. _________________ My art (and random photos)! |
|
Back to top |
|
 |
Bagne ALL YOUR NUDIBRANCH ARE BELONG TO GASTROPODA

Joined: 19 Feb 2003 Posts: 518 Location: Halifax
|
Posted: Mon Nov 09, 2009 5:43 pm Post subject: |
|
|
Yes, moving the "resume swap" worked - thanks!
One last question: neither typing "key:c" or "c" works for me. _________________ Working on rain and cloud formation |
|
Back to top |
|
 |
Pepsi Ranger Reality TV Host

Joined: 05 Feb 2003 Posts: 493 Location: South Florida
|
Posted: Mon Nov 09, 2009 7:20 pm Post subject: |
|
|
Quote: | One last question: neither typing "key:c" or "c" works for me. |
I believe you have to include scancode.hsi at the top of your plotscript file first. They're not actually included by default. _________________ Progress Report:
The Adventures of Powerstick Man: Extended Edition
Currently Updating: General sweep of the game world and dialogue boxes. Adding extended maps.
Tightfloss Maiden
Currently Updating: Chapter 2 |
|
Back to top |
|
 |
Bagne ALL YOUR NUDIBRANCH ARE BELONG TO GASTROPODA

Joined: 19 Feb 2003 Posts: 518 Location: Halifax
|
Posted: Mon Nov 09, 2009 7:26 pm Post subject: |
|
|
Bingo! _________________ Working on rain and cloud formation |
|
Back to top |
|
 |
|