Game Development Community

Key bind Question

by JD Scogin · in Torque Game Builder · 09/03/2007 (9:45 am) · 2 replies

Is there a way to tell if a key is still pressed?

Here is the code:

moveMap.bindObj(getWord($myUp, 0), getWord($myUp, 1), "moveUp", %this);
   moveMap.bindObj(getWord($myDown, 0), getWord($myDown, 1), "moveDown", %this);
   moveMap.bindObj(getWord($myLeft, 0), getWord($myLeft, 1), "moveLeft", %this);
   moveMap.bindObj(getWord($myRight, 0), getWord($myRight, 1), "moveRight", %this);

$myup ... is a variable so I can changed the keys)

When a key is pressed, my player moves a certain distance.
I need to be able to check to see if the key is still pressed so he can keep moving or stop.
Having trouble finding how to do this.
I am sure it is in the docs, but I just can't seem to find it.
Thanks
Jd

#1
09/03/2007 (12:02 pm)
I believe that the way bindObj works, you receive the function calls with an argument of '1' for keydown and '0' for keyup. I'm pretty sure that 'bind' works that way if 'bindObj' doesn't.
Also, if you use bindCmd, you can specify a keydown function and a keyup function.
In my opinion, bindCmd is way better because the functions are actually 'eval'ed so you have way more flexibility.
Sorry my answer is so unsure... don't have the docs right in front of me.
#2
09/03/2007 (12:48 pm)
Bingo!
Yea, I think you are correct.
I just need to set a variable to know when it is up or down.
Thanks