Game Development Community

Schedules & Timers for Multiple Instances

by Leo Gura · in Torque Game Builder · 09/17/2006 (8:34 pm) · 1 replies

I'm trying to create many instances of the same class called "enemyShip". Each time an instance is created it sets a schedule for 3 seconds to call a function which applies a force to the object. When I have one instance everything works fine, but when I create more than one, it seems that the schedules start to intefere with one another. What is the proper way to set a schedule for just a single instance, so that it doesn't conflict with other schedules?

Here's my code:

function enemyShip::generate(%this)
{
$enemyShipID = %this;
%this.setConstantForceY(500);
schedule(3000,$enemyShipID,"enemyOscillation");
}

function enemyShip::enemyOscillation()
{
$enemyShipID.setConstantForceY(1000);
schedule(3000,$enemyShipID,"enemyOscillation");
}


Also, I tried using the setTimer function as well and also get interferance when multiple objects were created and each set a timer and used the OnTime event.

#1
09/17/2006 (11:14 pm)
The global, $enemyShipID, is always the last enemy ship you create. Try this instead...

function enemyShip::generate(%this)
{
   %this.setConstantForceY(500);
   %this.schedule( 3000,enemyOscillation ); 
}

function enemyShip::enemyOscillation(%this)
{
   %this.setConstantForceY(1000);
   %this.schedule(3000, enemyOscillation);
}