Game Development Community

Changing levels when all enemys are defeted

by Richard Pettyjohn · in Torque Game Builder · 06/30/2006 (1:25 pm) · 8 replies

I need some help with changing levels after all enemys are defeated. I think I can do for just on level by having a global variable called $enemyCount and the value being the number of enemys in the level, then having $enemyCount-- and checkEnemyCount(); in the explode function for the enemy ships. Then I'll have the function checkEnemyCount which if the enemy count is 0 then the next level will be loaded.

The problem I'm having is while this should work for one level I'm not sure how to make it work for multiple levels. Could somebody please tell me the best way to do this.

#1
07/02/2006 (6:04 pm)
Ok here's what I got but for some reason it crashes after I have defeated all the enemys:


$enemyCount = 4;
$levelNumber = 1;


function checkEnemyCount()
{
if($enemyCount<1)
{
nextLevel();
}
else
{

}
}

function nextLevel()
{
if($levelNumber = 1)
{
levelOne();
}
else
{

}
if($levelNumber = 2)
{
levelTwo();
}
else
{

}
}

function levelOne()
{
sceneWindow2D.loadLevel("scrollerDemo/data/levels/leveltwo.t2d");
$enemyCount = 8;
$levelNumber = 2;
}

function levelTwo()
{
sceneWindow2D.loadLevel("scrollerDemo/data/levels/levelthree.t2d");
$enemyCount = 6;
$levelNumber = 3;
}

This is only for the fist two levels and it crashes after the first.
#2
07/02/2006 (6:18 pm)
Without looking over the code that much, you need to use "==" for comparing numbers, not "=". You're probably trying to load both levels at once like that and it's blowing up.
#3
07/02/2006 (7:29 pm)
It still crashes with ==. But it does seem to be trying to load both levels at once, since during the rare times that it doesn't crash it loads the third level.
#4
07/03/2006 (1:28 pm)
I just tried it with one level... it crashed. So there must also be a problem with my sceneWindow2D.loadLevel but I have know clue what it is.
#5
07/03/2006 (1:34 pm)
Try using ~/data/levels/LEVEL.t2d instead of scrollerDemo.

Also, try using $= instead of ==, because if I remember == was broken for something or other.

Tip: use [ code ] [ /code ] Tags, without the spaces. :)
#6
07/03/2006 (2:39 pm)
It still crashes with $= and ~.
#7
07/03/2006 (3:57 pm)
I replaced the lodLevels with echos and both mesages apear with "=" or "==" or "$=".
#8
07/04/2006 (4:19 pm)
Nevermind I fixed iit.