Posted: Sat Jan 29, 2005 12:51 pm Post subject: help with double tapping
hey, im making a game, and I want the player to be able to double tap the right/left arrow keys to load my run procedure, or just tap it once to load the walk procedure
can somebody help me make a timer, or maybe you could help me use another method to solve my problem, your help is appreciated
Sponsor Sponsor
Cervantes
Posted: Sat Jan 29, 2005 1:08 pm Post subject: (No subject)
What have you got so far? If you don't have code yet (which is fine), what are your ideas?
Chaos_Theory
Posted: Sat Jan 29, 2005 1:22 pm Post subject: (No subject)
Cervantes wrote:
What have you got so far? If you don't have code yet (which is fine), what are your ideas?
yah I have some coding:
code:
var Actions : array char of boolean
var FaceRight : boolean := false
process Controls
Input.KeyDown (Actions)
Stand
If Actions (KEY_RIGHT_ARROW) then
FaceRight := true
Walk
elsif Actions (KEY_LEFT_ARROW then
FaceRight := false
Walk
end if
if Actions (KEY_UP_ARROW) then
Jump
elsif Actions (KEY_DOWN_ARROW) then
Crouch
end if
end Controls
fork Controls
I alsoy have the procedures, but i don't think you should need them to help me, I just need to find a way to allow a double tap so it loads the run instead of the walk, so can you help me?
person
Posted: Sat Jan 29, 2005 2:16 pm Post subject: (No subject)
u can do this (havent tested it):
code:
mousewhere (x,y,button)
if button= 0 or button = 100 then
mousewhere (x1,y1,button1)
if button1= 0 or button1 = 100 then
% do wat ever
end if
end if
hope this helps
Delos
Posted: Sat Jan 29, 2005 6:29 pm Post subject: (No subject)
person...what on Earth was the point of that?
Seriously, Chaos_Theory needs help on double tapping on the Keyboard...not anything to do w/ the Mouse...
[sigh]
[/mini-rant]
Ok, I'm good.
Let's see...your code isn't bad...I don't like the processes use, but that's just me. Okay, it's not just me - it's about five dozen other ppl around here too.
Anyhow...in terms of double tapping, you could try this idea:
- detect first input. Do something. Set a boolean var to true (i.e. 'FirstTap := true")
- detect second input. If FirstTap is true, then do the second something.
- reset FirstTap everynow and then.
Otherwise...a better method:
- detect first tap. Do something. Record the Time at which tap occured.
- detect second tap. If a sufficient amount of time has passed, or if the tap is within a particular range of time, do the second something.
- it would be even better if instead of Time.() stuff, you used an FPS check...this would ensure some cross-computer compatability...
But just try to get if working first, then you can add in the other stuff. :p.
BTW, no offense person...hehe.
person
Posted: Sat Jan 29, 2005 6:31 pm Post subject: (No subject)
sorry about that
AsianSensation
Posted: Sat Jan 29, 2005 6:55 pm Post subject: (No subject)
you know, I think your incessive spamming should stop, consider this as a warning.
- all bits
Anymore of this type of behavior will result in banning. Go ahead and post nonrelevent stuff in the Spam section, but posting irrelevent code and one-liners only distracts other people seeking help.
Chaos_Theory
Posted: Sat Jan 29, 2005 7:58 pm Post subject: (No subject)
heh, I just thought of something myself, It doesnt quite work, but if soemoen can help me to make it work, i would be very greateful
code:
var Actions : array char of boolean
var DoubleTap : boolean := false
loop
DoubleTap := false
Input.KeyDown (Actions)
if Actions (KEY_RIGHT_ARROW) then
delay (100)
for i : 1 .. 10
Input.KeyDown (Actions)
delay (100)
if Actions (KEY_RIGHT_ARROW) then
DoubleTap := true
end if
end for
if DoubleTap = true then
put "Run!"
else
put "walk..."
end if
end if
end loop
now... since this is to walk or run, the player needs to hold the button when they press it, so if you press once and hold it is supposd to walk, but if you press then press again and hold real fast it should run, but, in mine teh way I have it if you hold it he runs no matter what... so could someone help? or is what im asking for impossible on turing?
Sponsor Sponsor
basketball4ever
Posted: Sat Jan 29, 2005 8:12 pm Post subject: (No subject)
Quote:
now... since this is to walk or run, the player needs to hold the button when they press it, so if you press once and hold it is supposd to walk, but if you press then press again and hold real fast it should run, but, in mine teh way I have it if you hold it he runs no matter what... so could someone help? or is what im asking for impossible on turing?
i honestly have no clue how to do it... but heres what i know...
in turing... it stores up the things u press on the keyboard... basically... if i hold down the right arrow... and the program isn't fast enough... it'll keep pressing the right arrow. I dont know... but that might make ur program a lil buggy. I dont recommend turing for what you're trying but yeh. I might be just wrong .
Couldn't you just do it, that if they're press shift... and then press the right key, it runs, and if they press shift again... they stop running?
person
Posted: Sat Jan 29, 2005 8:25 pm Post subject: (No subject)
im not sure this will work, but i think getch will work
Trojan Man
Posted: Sat Jan 29, 2005 11:14 pm Post subject: (No subject)
I see that you tried using delay in your code, but that won't work well because holding down the key will do the same, unless you start the delay after the button was released, but if you make a delay it also slows your program down, making your program halt between two key clicks.
Quote:
can somebody help me make a timer, or maybe you could help me use another method to solve my problem, your help is appreciated
Do you need the timer just to time your program or to determine the time of double clicking?
If you want to just time your program by putting something like this at the end of your program:
code:
var timeRunning : int
timeRunning := Time.Elapsed
put "This program has run ", timeRunning, " milliseconds"
OR You can use the same command to time the amount between each of the double clicks, you'll just need to have it in a loop. Except I'm not quiet sure what you'd have to have in your if statement. I'm guessing you'd have to like start the timer when the button was released and end the time (exit the loop) if it ran for more than like 2000 miliseconds or if the button was clicked. And then make an if structure that checks if the same button was pressed in the period between the button release and the 2 seconds.
Quote:
Couldn't you just do it, that if they're press shift... and then press the right key, it runs, and if they press shift again... they stop running?
In my opinion this would make more sense, you wouldn't have to use the timer and stuff, besides that's what all the modern shooter games use.
Quote:
im not sure this will work, but i think getch will work
Getch will not work when inputting multiple keys, that's why we have to use Input.KeyDown.
EDIT: If you're gonna use my method, note that when you put it in the loop it, it should look like this:
code:
var timeRunning : int
loop
timeRunning := Time.Elapsed
put "This program has run ", timeRunning, " milliseconds"
exit when timeRunning >= 2000
end loop
First: your loop has to go around the Time.Elapsed so that it increases everytime, and it has to exit when it's either more or equal to 2000, NOT just equal to 2000 because the loop doesn't repeat every milisecond, so its can't always be equal to 2000. My comp's slow (XP 2800+) it takes him about 13-14 mileseconds to restart the loop.
Cervantes
Posted: Sun Jan 30, 2005 8:27 am Post subject: (No subject)
basketball4ever wrote:
in turing... it stores up the things u press on the keyboard... basically... if i hold down the right arrow... and the program isn't fast enough... it'll keep pressing the right arrow. I dont know... but that might make ur program a lil buggy. I dont recommend turing for what you're trying but yeh. I might be just wrong .
Good point. But with some boolean variables, you should be able to make it work just fine.
Chaos_Theory: There's a major problem with the last bit of code you posted: you've got a for loop inside your main loop (well, it's inside the if Actions statement, but that's inside your main loop). That for loop contains some pretty hefty delays. Thus, as soon as you hit KEY_RIGHT_ARROW, you delay for 100 milliseconds, enter the for loop, delay for another 100 milliseconds, check for KEY_RIGHT_ARROW, delay another 100 milliseconds... See, the rest of your program is not running while you're inside that for loop. And copying and pasting all the code of your program inside that for loop is not a good idea! Same with using a procedure that contains all the code of your program.
Delos outlined what you should be doing quite nicely. The only thing is, you will have to solve the problem that basketball4ever outlined. Boolean variables will be your friend.
-Cervantes
Chaos_Theory
Posted: Sun Jan 30, 2005 2:46 pm Post subject: (No subject)
OMFG XD I've almost got it^^ actually i think i did just get it... (just a little hard to tell cause i'm only testing it with text (so that you people can coppy and paste it to check if it works) lol
code:
var Actions : array char of boolean
var Walk : array char of boolean
var Run : array char of boolean
var SingleTap : boolean := false
var DoubleTap : boolean := false
if Actions (KEY_RIGHT_ARROW) then
for i : 1 .. 10
Input.KeyDown (Walk)
if Walk (KEY_RIGHT_ARROW) then
SingleTap := true
else
SingleTap := false
end if
delay (10)
end for
for i : 1 .. 10
Input.KeyDown (Run)
if Run (KEY_RIGHT_ARROW) and SingleTap = false then
DoubleTap := true
else
DoubleTap := false
end if
delay (10)
end for
if SingleTap = true then
put "walk..."
elsif DoubleTap = true then
put "Run!"
end if
end if
end loop
well, if that works.. then... I've finnaly figured it out and thanks every one for your help... and if not, then I'd appreciate if you fixed it up for me 8)
oh, and to cervantes, the delays are no problem, cause this will be in a process so it runs individually form teh rest of the program^^
Cervantes
Posted: Sun Jan 30, 2005 3:28 pm Post subject: (No subject)
Chaos_Theory wrote:
oh, and to cervantes, the delays are no problem, cause this will be in a process so it runs individually form teh rest of the program^^
Uh oh.
Processes = death.
We'll allow Hacker Dan to explain:
Hacker Dan wrote:
I whould not recomend process for this, probly best to make one main loop with deals with eveything. Process can be good but you have to understand how they work and turing has limited conortl over them. Since turing has no way to set proity of a process all you know is that the code may run at some time. So baliky unless you got a dual CPU system a process will run lines of code in it at basicly random times durning the excution of your progame. If it dose not mater when they run then it could be good to use them but it gives you less conortl over things.
Even if you are using this in a process (and we'll ignore the sin for the moment), things will be slowed down. The way you've got it, you can't determine whether he's running or walking until after you've gone through those for loops. And that means that the rest of your program is not thinking your character is running or walking (whicher he is) until a while after you hit the key.
Turing:
var Actions :arraycharofboolean var tap :=false var speed :="" var timer :=0 const doubleHitTime :=300
if Actions (KEY_RIGHT_ARROW)and tap =falsethen
tap :=true ifTime.Elapsed - timer < doubleHitTime then
speed :="run" else
speed :="walk" endif
timer :=Time.Elapsed endif ifnot Actions (KEY_RIGHT_ARROW)then
tap :=false endif locate(1, 1) put speed
endloop
Chaos_Theory
Posted: Sun Jan 30, 2005 5:19 pm Post subject: (No subject)
I use to processes in my program... one called getkey
which is bacially just a gech, but it allows the program to contune while waiting for the input... (which is nessesary... nothing wrong with that one... )
and then Controls ,the reason why i chose to use it... is becasue processes run seperatly from the rest of the program, and all it is ; is a process that checks what key is being pressed and does teh appropriate action, where it loads a procedure, but because this procedure is inside a process, it is also run seperate from the main propraram... and thus you can move your character (which requires delaying so the pictures don't cycle through madly fast) and also doesn't delay teh rest fi teh program... if you can tell me another way of doing taht without using a proces.s.. then I'll agree with you but until then, I will continue to use processes.