[fixed] trick to using schedule command
by Jeff Yaskus · in Torque Game Engine · 03/11/2010 (1:29 pm) · 2 replies
I'm having some trouble setting up a scheduled command properly.
I place down a new building (%b) which works fine.
Then I add a scheduled command to have it spawn a unit ...
%b.AItrain(8000,...);
this gets called immediately without the expected wait.
which is bad, because the end of the function ... it spawns another .. and another, until the game crashes.
I place down a new building (%b) which works fine.
Then I add a scheduled command to have it spawn a unit ...
%b.AItrain(8000,...);
this gets called immediately without the expected wait.
which is bad, because the end of the function ... it spawns another .. and another, until the game crashes.
// -------------------------------------
function RTSUnit::AiTrain(%this,%index,%conn)
{
echo("c2 AiTrain -- enter");
%state = %this.getState();
// cancel any pending spawns if building is destroyed
if ( (%state $= "Dead") || (! isObject(%this)) )
{
echo("AI building destroyed - canceling its build cycle");
cancel(%this.spawnAI);
return;
}
// location to build unit
%location = %this.getId().getTransform();
%startX = getWord(%location, 0);
%startY = getWord(%location, 1);
%location = %startX SPC %startY SPC "250" SPC "0 0" SPC %conn.getTeam();
// build the unit
%conn.createPlayer(%location, %index);
MapHud.createPingEvent(%startX SPC %startY, "1 0 0"); // red ... DEBUG (JY)
// determine the next unit to spawn
%newUnit = getRandom(4,6);
// and time to build it
switch(%newUnit)
{
case 4:
%builtTime = 4000; // 4s
case 5:
%builtTime = 8000; // 8s
case 6:
%builtTime = 9000; // 9s
}
// create next spawn
%this.spawnAI = %this.schedule(%buildTime,"AiTrain",%newUnit,%conn);
echo("c2 AiTrain -- exit");
}About the author
Long time gamer, hacker and programmer. With dreams of making video games -
Torque 3D Owner Thomas Huehn