How do I use schedule();?
by Tyler Slabinski · in Torque Game Builder · 05/14/2009 (6:55 pm) · 2 replies
function t2dSceneWindow::onLevelLoaded()
{
$waitVariable = 1;
}
function shootArrow()
{
if ($waitVariable = 1)
{
$waitVariable = 0;
%this = new t2dStaticSprite()
{
scenegraph = SceneWindow2D.getSceneGraph();
position = "-44.0 -9.5";
size = "5.000 5.000";
imageMap = "normalArrowImageMap";
class = "normalArrow";
CollisionActiveSend = "1";
CollisionActiveReceive = "1";
CollisionResponseMode = "KILL";
CollisionPolyList = "-0.250 -0.250 0.250 -0.250 0.250 0.250 -0.250 0.250";
ConstantForce = "0.000 35.000";
ConstantForceGravitic = "1";
mountID = "20";
WorldLimitMode = "KILL";
WorldLimitMin = "-50.000 -85.000";
WorldLimitMax = "50.000 20.000";
};
//Set the speed for the arrow.
%this.setLinearVelocityX($arrowX);
%this.setLinearVelocityY($arrowY);
//Update the arrow and rotate
%this.enableUpdateCallback();
schedule(50000, 0, "reload");
}
}
function reload()
{
$waitVariable = 1;
}Ok, the above code is a snipped piece of my script I made to take 50000 ms to reload (as a pausing time to keep players from spamming projectiles).
Basically, this is what it does:
function t2dSceneWindow::onLevelLoaded()
{
$waitVariable = 1;
}The above code makes the $waitVariable start as 1 when the level gets loaded.
function shootArrow()
{
if ($waitVariable = 1)
{
$waitVariable = 0;
%this = new t2dStaticSprite()
{
scenegraph = SceneWindow2D.getSceneGraph();
position = "-44.0 -9.5";
size = "5.000 5.000";
imageMap = "normalArrowImageMap";
class = "normalArrow";
CollisionActiveSend = "1";
CollisionActiveReceive = "1";
CollisionResponseMode = "KILL";
CollisionPolyList = "-0.250 -0.250 0.250 -0.250 0.250 0.250 -0.250 0.250";
ConstantForce = "0.000 35.000";
ConstantForceGravitic = "1";
mountID = "20";
WorldLimitMode = "KILL";
WorldLimitMin = "-50.000 -85.000";
WorldLimitMax = "50.000 20.000";
};
//Set the speed for the arrow.
%this.setLinearVelocityX($arrowX);
%this.setLinearVelocityY($arrowY);
//Update the arrow and rotate
%this.enableUpdateCallback();
schedule(50000, 0, "reload");
}
}This part makes nothing happen unless $waitVariable is equal to 1.
It then defines $waitVariable to be 0, and then creates a projectile and sets the velocities and the callback. Then it schedules the reload function 50000 ms later.
function reload()
{
$waitVariable = 1;
}Defines $waitVariable to 1 so that the cycle may start again.
This is the first time I have used the schedule function like this, so I know I am unfamiliar with this function. Anyone got any advice?
About the author
Working on prototype.
Associate Phillip O'Shea
Violent Tulip
with this: