Game Development Community

Ending missions and moving to the next level

by Caleb Rogers · in Torque Game Engine · 01/13/2007 (6:21 pm) · 1 replies

OK, I'm still a TGE noob, but I've managed to get a couple of basic levels built. The problem is, I haven't really been able to figure out the best way to end a mission and then start the next one.

I've been looking through server/scripts/game.cs in the FPS Shooter example, and I think I see where I need to add the script, but I don't really know what to do and exactly where to put it. It looks like onMissionEnded and onMissionLoaded would be the two I need to deal with, but I'm not sure.

If I have a level where I want to kill all the bad guys, the level would end after the player has dispatched them all, then the game would move on to the next level/mission. I suppose I could set up some type of enemy count, but that number would vary from mission to mission.

I'm not really asking anyone to write the script for me, but if someone could at least point me in the right direction, then I could figure it out for myself. Thanks.

#1
01/13/2007 (7:25 pm)
You could try something like this:
//every time you create a bad guy that counts toward
//the player finishing the level, feed it to this function
function badGuyCreated(%badguy)
{
    if(!isObject($BadGuyList)) 
    {
        $BadGuyList = new SimSet();
    }
    $BadGuyList.add(%badguy);
}

//every time a bad guy is killed, feed it to this function
//before it is deleted
function badGuyKilled(%badguy) 
{
    $BadGuyList.remove(%badguy);
    if($BadGuyList.getCount() == 0)
    {
        schedule(200,0,missionDidEnd);
    }
}

function missionDidEnd()
{
    //load a new mission here
}

You might also want to look at this link regarding switching missions:
http://www.garagegames.com/mg/forums/result.thread.php?qt=33492