Tapping twice to dash/double - jump etc. Please help.
|
|
Johnny Mann
Registered User
Join date: 1 Oct 2005
Posts: 202
|
08-30-2006 05:27
Hey Guys,
Im making a weapon when worn allows you to dash forward using push.
I have the push portion down however double tapping is just not working.
I have tried two different styles and neither work for me.
1) (basically a tree. if user presses foward, then forward again...dash)
If (user pressed CONTROL_FWD) { If (user pressed CONTROL_FWD) { Pushowner }
2) (uses a timer and different states)
if (user presses fwd) state two;
state two { If (user pressed CONTROL_FWD) { Pushowner
Neither of these formats work and I have no idea why. can someone help me?
Thanks
|
|
Ayrn Wake
Registered User
Join date: 7 Jan 2006
Posts: 39
|
08-30-2006 08:27
without coding it, heres the process (semi-pseudo code, so just giving the idea on what structure you need to do):
on press_forward and dash = true -> push user
on press_forward -> dash = true -> timer 0.5 secs (or however long you want the double tap cooldown to be)
on timer -> dash = false
If you have the button presses the other way around, it'll dash on single tap i think. The bonus of this method / structure is that every button press after the second should apply another push. If I could be bothered I'd code the thing for you, but I'm lazy, so that will have to do.
|
|
Johnny Mann
Registered User
Join date: 1 Oct 2005
Posts: 202
|
08-30-2006 10:39
From: Ayrn Wake without coding it, heres the process (semi-pseudo code, so just giving the idea on what structure you need to do):
on press_forward and dash = true -> push user
on press_forward -> dash = true -> timer 0.5 secs (or however long you want the double tap cooldown to be)
on timer -> dash = false
If you have the button presses the other way around, it'll dash on single tap i think. The bonus of this method / structure is that every button press after the second should apply another push. If I could be bothered I'd code the thing for you, but I'm lazy, so that will have to do. Thank you so much!
|
|
HtF Visconti
Registered User
Join date: 21 Jul 2006
Posts: 123
|
08-31-2006 03:18
You already have the solution with the previous post but I'd like to point out the logical error in your first attempt. The events are processed in order and run through their code before being re-triggered. So if you press any key twice the second keystroke waits in a queue until the first keystroke is processed and is then processed sequentially.
You cannot check for additional keystrokes in the queue so you must buffer the fact that a key has been pressed (like the example above tells you) and then, when that key is found being pressed check if it has been pressed before - thus assuming that it was double pressed.
The example above is a bit rudimentary ... I'd reset the variable on the following conditions:
1. timer based (to make sure two presses which happen after a second or so are not interpreted as a double tap).
2. if any other key is pressed and the variable is true I'd set it to false as well. So you wouldn't press forward, step right press forward again and be pushed.
In addition to that I'd program the timer so that it starts when the key is pressed the first time, set it to a small time, maybe 0.5 seconds, then in the timer loop I'd delete it, in the check key control event I'd delete it first thing into the function. This should put less load on the sim.
|
|
Johnny Mann
Registered User
Join date: 1 Oct 2005
Posts: 202
|
08-31-2006 05:29
From: HtF Visconti You already have the solution with the previous post but I'd like to point out the logical error in your first attempt. The events are processed in order and run through their code before being re-triggered. So if you press any key twice the second keystroke waits in a queue until the first keystroke is processed and is then processed sequentially.
You cannot check for additional keystrokes in the queue so you must buffer the fact that a key has been pressed (like the example above tells you) and then, when that key is found being pressed check if it has been pressed before - thus assuming that it was double pressed.
The example above is a bit rudimentary ... I'd reset the variable on the following conditions:
1. timer based (to make sure two presses which happen after a second or so are not interpreted as a double tap).
2. if any other key is pressed and the variable is true I'd set it to false as well. So you wouldn't press forward, step right press forward again and be pushed.
In addition to that I'd program the timer so that it starts when the key is pressed the first time, set it to a small time, maybe 0.5 seconds, then in the timer loop I'd delete it, in the check key control event I'd delete it first thing into the function. This should put less load on the sim. I was able to sucessfully create a working script in the fashion the previous user was giving an example of. Only pressing foward makes my dash varible true. so this is what Ive done basically:
if (held & change & CONTROL_FWD) {
if (!DASH) {//my varible, DASH, is default FALSE
llSetTimerEvent(0.5); DASH = TRUE;
if (DASH) {
//all my push object sh*t goes here DASH = FALSE;
//onto an example for the timer event
timer() {
DASH = FALSE;
This seems to be working great for me
|
|
HtF Visconti
Registered User
Join date: 21 Jul 2006
Posts: 123
|
08-31-2006 05:53
I am not 100% sure about this and I am not sure this is all of the code you use but humour me and put in an llOwnerSay("Timer event executing"  ; in your timer loop - just above the line where you set your variable to false again.  If I am right even when you stand perfectly idle and do nothing you should get - once you have pressed the magic key once - the message that your timer event is executing, executing, executing ...... It will not do much - it will just reset the variable to false but it will be executed every 0.5 seconds and is absolutely unneccessary if the variable has already been set to false.  So - if I am right and you see this message more than once, please add llSetTimerEvent(0); right after your timer start. You will not need this timer to run endlessly and once you press the key with your variable set to false it will be re-created and fire 0.5 seconds later. I addition you can ise llSetTimerEvent(0) also when your variable *IS* true - you know that you'll have to push and you set the variable to false afterward - no need to keep the timer running and generating an event that will just reset the already reset variable. My "tip" is assuming the WIKI info is right and a timer is a recurring event. Should you stop the timer somewhere in syour script, please disregard my entire post. Should you not and getthe message only once(!) a feedback would be apprechiated. 
|
|
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
08-31-2006 09:23
I do this for several movement scripts. No real need for a timer event. Instead, capture the time when a key is pressed with 'llGetTime()' and then the next time a key is pressed grab the time again and test on the amount of time that elapsed (the difference) to see if it is greater or less than a timeout value.
|
|
HtF Visconti
Registered User
Join date: 21 Jul 2006
Posts: 123
|
08-31-2006 09:55
Hewee - once again I bow to you! Much better - no pesky timer eating up ressources. 
|
|
Johnny Mann
Registered User
Join date: 1 Oct 2005
Posts: 202
|
08-31-2006 10:15
From: Hewee Zetkin I do this for several movement scripts. No real need for a timer event. Instead, capture the time when a key is pressed with 'llGetTime()' and then the next time a key is pressed grab the time again and test on the amount of time that elapsed (the difference) to see if it is greater or less than a timeout value. Ok interesting ... so you make 2 float variables Time #1 Time #2 Then subract time one from time 2 and if the remainder equals more than .5 seconds then the varible equals false once again?
|
|
SqueezeOne Pow
World Changer
Join date: 21 Dec 2005
Posts: 1,437
|
Tappy Tappy!
10-02-2007 13:57
So I'm trying to work off of http://wiki.secondlife.com/wiki/Double_Tap_Detection to make what you guys are talking about for my project. I can get it to register the double tap, but I have to tap it at a certain rhythm...about exactly .5 seconds as the script shows. Any faster or slower and it doesn't register. I tried adjusting the .5 and some of the other numbers relating to time, but I can't get it to respond any differently. I want it to be able to register a double tap that's about as fast as your average computer user does a double click on the mouse but I don't want it to require you to do it at an exact time. Any ideas? Thanks!
_____________________
Semper Fly -S1. Pow
"Violence is Art by another means"
Visit Squeeze One Plaza in Osteria. Come for the robots, stay for the view!http://slurl.com/secondlife/Osteria/160.331/203.881
|