Game Development Community

Trying to write a "On release" function

by Matthew Jones · in Torque Game Engine · 12/27/2002 (5:53 pm) · 9 replies

I am trying to write a function for the "Move forward" action that only allows a certian amount of move forward everytime you release the key. Except I have no clue. I have been reading and looking through the code for an example but can't seem to find anything for a tamplate for the function. How would I go about it.
The forward code is:
function moveforward(%val)
{
   $mvForwardAction = %val;
}

Is there a script command that would allow me to do this and am I on the right track.

Sorry if this is stupid simple or whatever I am just not familier with the scripting.

Matt

#1
12/28/2002 (5:28 am)
You might want to take a look at the updateMove function in player.cc. This is where the player movement is updated. move->y will tell you if the player is moving. If it is 1 then the player asked to move forward. If it is -1 then the player asked to move backward. If it is 0 then there was no forward/back movement.


Hope this helps.
-d
#2
12/28/2002 (12:47 pm)
I really trying to avoid having to modify the code. I would be more comfertable using the script to make this happen.
#3
12/28/2002 (1:23 pm)
I believe %val may be a "true" or "false" value, such that you could do something like:
if (%val) {
  // key was pressed down
} else {
  // key was released
}
#4
12/28/2002 (4:10 pm)
Ya thats what I was thinking. The value of move forward (for a vehicle) is 0 or 1. So I am assuming that, that mean 1 =true and 0 =false. The best I have been able to make it work it turns into a loop that makes the vehicle accelerate after the realese happens. I only need it to give a burst of power.
Is there syntax like "on release" or "on click" that would let me assign values to them? Does torque recognize the keys state in the script? ALso is there a way to designate the amount of time it might run that function.
I haven't been able to find anything other than an "on trigger down" and "...up" and I am not sure if that applies to movement.
Really all I need is some examples, maybe in a resource or already written script. I am not trying to have somebody write it for me. I wanna learn more that anything.

Thanks alot though, I do appriciate any help.

Matt
#5
12/31/2002 (5:34 pm)
Well we have tried to make a little headway with this but I have had no luck so far. We finally were able to figure out that the "DefaultCar.whatever();" gave us some control over the script settings and we tried to write a loop that would apply speed and torque for only a brief time then the vehicle would coast at the accumulated rate until the next time the forward key was pressed or top speed was reached. But anytime we use time for something nothing seems to not work.

Is there a way to find the vehicles velocity? I know you can get the speed from "getControlObjectspeed();". Can you set the speed? If not where in the CODE should I start looking to find a way to go about it?

I'll take some table scraps at this piont.

Thanks
Matt
#6
12/31/2002 (8:47 pm)
moveMap.bind(keyboard, "q", moveFonrelease);
moveMap.bind(keyboard, "r", moveBonrelease);

function moveFonrelease(%val)
{
if (!%val) {
$mvForwardAction = 1;
schedule(2000,0,"stopmovement",1);
}

}

function moveBonrelease(%val)
{
if (!%val) {
$mvBackwardAction = 1;
schedule(2000,0,"stopmovement",0);
}

}

function stopmovement(%dir)
{
echo("Stop: " @ %dir);
if(%dir)
{
$mvForwardAction = 0;
}
else
{
$mvBackwardAction = 0;
}
}

If you need some explanation of what's going on... let me know
#7
12/31/2002 (9:34 pm)
OHHH Thank you so much!!!

The one thing I do have a question about is the :
schedule(2000,0,"stopmovement",1);

Is this a time function or somthing? If you could break that one down for me so I could understand whats happening there that would be great. The rest I understand.

Also just to help out the storyline here we have been trying to set the vehicle speed without getting to fancy. Default car and wheeled vehicle can't be called from the script as an object. Finally we figured out that what we are looking for is the "%player" and not a vehicle. The stickler was we needed to change the player from a local to a global variable. So in the Racing/Game.cs file we change all instances of "%player" to "$player"/ That made a whole host of commands availible to us, 2 being of which were "setVelocity" & "getVelocity". This will allow us to set the speed via script functions and triggers.

I know that alot of reading I just like to fill in the blanks for whoever later on.

Thanks again Labrat

Matt
#8
12/31/2002 (10:27 pm)
schedule() is very cool.
it allows you to make a script function call happen in the future.

$mSched = schedule(ms_to_wait,obj,functionName,arg1,arg2,...argN);

to cancel the schedule:
cancel($mSched);

thats just basic usage, there is some more stuff you can do with it. I'm dont have access to my dev box right now, cant remember the other way to call it, sorry.

ah, wait... a fine tutorial exists, look in the 'Advanced Engine Functions' section:
www.liquid.nq.net/tutorial/
#9
01/01/2003 (5:22 am)
Thats a nice tutorial. I don'tthink I have ever ran accross that one.
Thanks alot for the definition. I see whats happening now.

Matt