Game Development Community

Just started scripting...rotation issue...

by Gareth Hewes · in Torque Game Engine · 01/27/2007 (3:32 pm) · 2 replies

SUPER N00B QUESTION!

Okay, I'm finally getting into the scripting part of Torque, not just the art. Now, I had a question about infinite 'while' loops.

See, coming from the 3D Game Studio scripting conventions, when I want to define an infinite loop, I think:

//------------------------------------------------------------------------------
while(1) // which is synonimous with while (game == running)
{
thisobject.pan+=angle of change;
wait(1);
}
//------------------------------------------------------------------------------

That made sense to me, meaning "while the game is running, continuously add 'angle of change' to the object's horizontal rotation and then wait 1 tick."

Now, I know obviously TorqueScript is a little different, and having read through the script overview, I know that it should be something like:

//------------------------------------------------------------------------------
while(what goes here for a constant loop?)
{
XXXX.rotation += angle of change; // where xxxx is the object's unique ID
// And do I add a time increment here?
}
//-------------------------------------------------------------------------------

OR, am I on the wrong track altogether? I was just wondering because these things were the backbone of most of my 3DGS scripting, with uses for anything from character position, AI, etc.

#1
01/27/2007 (3:41 pm)
Coming from a Tribes coding beginning, I'd go with scheduling a function over and over.

function Rotate(%obj,%rot)
{
%obj.setRotation(%rot++);
schedule(1, %obj, checkStartupDone );
}

I didn't test it, so I'm not 100% sure it works, but if it doesnt work the only thing that is wrong is the schedule, because I can't get used to the way torque schedules things.
#2
01/29/2007 (12:49 pm)
@Gareth:
I also started with 3DGS, and I've found that Toque works very differently. I *think* (don't quote me) that the action you describe, for example:
while(me != 0) { my.pan += 1 * time; }
All this stuff is done inside the actual c++ engine code. What the script in the .cs files does is call the functions defined by the engine code, and define the behaviour of objects through datablocks.
So think of datablocks as 'actions' in WED, except that they come with the skills predefined.
Of course, you can define functions in script and what you might do is have a startRotation(%this) function that starts it rotating, and a stopRotation() that stops it rotating. The actual rotation is handled by the engine.

I am pretty sure that's how most of the engine works, but you could probably use schedule(not sure what goes on in here) to get that effect, as Maxwell said.