Game Development Community

unstoppable Schedule HELP!

by Sharam Namdarian · in iTorque 2D · 06/16/2011 (7:13 pm) · 2 replies

Ok guys, I seem to have run into a massive problem.

I am attempting to code a system of randomly generated enemies that will cycle through schedules. Every time the schedule is called it will search a list and randomly select a predefined set of enemies to spawn. Over time this list of possibilities will expand through other variables.

Here is my code so far.

SpawnerBehavior is added to a spawner control object
foodClick is the class for an enemy type while foodClicker is the template.
beeClass is the class for the second enemy type while beeClasser is the template.

at this point there is only one possible combination possible, that is spawn1().





function spawnBehavior::onBehaviorAdd(%this)
{
//turns on the update
%this.owner.enableUpdateCallback();
$myScene = sceneWindow2D.getSceneGraph();
schedule (400,0 , spawnerCycle);
$id = schedule (400,0 , spawnerCycle);

}



function spawnerCycle()
{
schedule (1800, 0 , spawn1);
}

function spawn1()
{
schedule(300,0,spawnFly);
schedule(600,0,spawnBee);
schedule (400, 0 , spawnerCycle);
}


function spawnFly()
{
%spawnObject1 = foodClicker.cloneWithBehaviors();
%spawnObject1.setLinearVelocityX(100);
%ypos = %spawnObject1.getPositionY() + getRandom(-50,50);
%spawnObject1.setPositionY(%ypos);
%spawnObject1.schedule(9000, Delete);
}

function spawnBee()
{
%spawnObject2 = beeClasser.cloneWithBehaviors();
%spawnObject2.setLinearVelocityX(100);
%ypos = %spawnObject2.getPositionY() + getRandom(-50,50);
%spawnObject2.setPositionY(%ypos);
%spawnObject2.schedule(9000, Delete);
}





The problem is that the cycle continues once I close the game in iTorque, replicating itself over and over again until the template objects are smothered with the two enemy types. I didn't realise that the code would still run scripts such as schedules even outside of running the game. I can't seem to stop the schedule.

Note: If I remove object names and re-add the template names at a later point (such as BeeClasser to the BeeClass spawn template) the cycle starts again outside of the game window and it just continues to clone these objects!




#1
06/16/2011 (7:37 pm)
Ok, Solved.

I just changed the names of the templates from say BeeClasser to BeeClassTemplate and now the cycle does not continue.

But just one last question...

How do I test if an object exists or if a number of object exist?
#2
06/17/2011 (5:37 am)
you can try the follwing:

if( isObject(%object) == true ){

}