Game Development Community

main loop in torquescript

by BlewScreen · in Torque Game Engine Advanced · 06/18/2009 (7:50 am) · 6 replies

Hi All,

I feel like a fool because of the question I'm going to ask seems a beginners question.
I want to start adding some dynamic objects via torquescript into my game. Objects that move by themselves.
Unfortunately I can't seem to find any main loop (that loops every frame) in the script files.
Am I looking for something that doesn't exist?
Can someone point me where to find it, if it exists?

Thanks in advance.

#1
06/18/2009 (8:45 am)
You can use the AI scripts for this. The FPS example shows Kork using a simple path to move.

The main loop is in the code, not the scripts. It calls script functions. For AI I'm using the "think" function which then calls into the pathing code to cause the AI to move. So far I have only put in a path and had my AI walk it so I can't offer much more than that.

If you want something more robust than the simple path, you can search for navmesh in the forums. I found some code for A* pathing and a navmesh I've built into my engine, but I haven't tried using it yet. Others have and with some success, though.
#2
06/18/2009 (10:11 am)
Pathed movement is one way.

To fill in some information about recurring or "looping" actions in Torque Script, you might want to read up on the schedule command. It allows you to repeat a given function every 'X' milliseconds. These can be repeated indefinitely, or you could set up a counter, and depending on how you set them up they can be cancelled at anytime.
#3
06/23/2009 (1:58 am)
But for your information, a 'main loop' is indeed something that doesn't exist in scripts, like Judy said. Th game's main loop and all the updating of objects is done in engine code, not in scripts - scripts primarily handle one-off responses to events that are caused by the code.
#4
06/23/2009 (3:10 am)
Thanks for all the info.
This helps me a lot. I guess I'll try that schedule command first, it's the closest thing to what I am looking for.
It isn't exactly AI that I want to move at the moment.
#5
07/17/2010 (8:10 pm)
Hello

How do you translate an object, for example a TSStatic object? I have this function:

function moveTremblingFloor()
{
warn("Dentro de la funcion moveTremblingFloor");

%testCubeTransform=testCube.getTransform();

%testCubePosX=getWord(%testCubeTransform, 0);
%testCubePosY=getWord(%testCubeTransform, 1);
%testCubePosZ=getWord(%testCubeTransform, 2);
%testCubeXRot=getWord(%testCubeTransform, 3);
%testCubeYRot=getWord(%testCubeTransform, 4);
%testCubeZRot=getWord(%testCubeTransform, 5);
%testCubeAngle=getWord(%testCubeTransform, 6);

testCube.setTransform(%testCubePosX+0.05 @ " " @ %testCubePosY @ " " @ %testCubePosZ @ " " @ %testCubeXRot @ " " @ %testCubeYRot @ " " @ %testCubeZRot @ " " @ %testCubeAngle);
//testCube.setTransform("1 1 1000 1 0 0 0");
error(testCube.getTransform());
schedule(500, 0, moveTremblingFloor);
}

moveTremblingFloor();

And you can see that the getTransform changes by increments of 0.05 in X but testCube doesn't move!! how can I make it move?
#6
08/06/2010 (5:19 am)
Agustin What does testCube mean? is it an object referenced somewhere else. If it is suppose to referenced does it have the correct name? This just looks like the testCube object wasn't named testCube. So when you run the script the script does not know where testCube is so it doesn't make any changes to it.