Game Development Community

RPG Zoning

by Kevin Mitchell · in Torque Game Engine Advanced · 01/11/2009 (5:27 am) · 2 replies

Well I've just spent 3 day trying to figure out how to load a new map after zoning from a previous map. I'm not 100% sure this is the best way. I took the destroy script and revamped it like so.



function MoveToNewMap(%MapName)
{
// Delete the connection if it's still there.
if (isObject(ServerConnection))
ServerConnection.delete();

// Call destroyServer in case we're hosting
destroyServer();

// Clean up any client-side stuff left over
MoveToNewMapCleanup(%MapName);
}

function MoveToNewMapCleanup(%MapName)
{
if( isObject(ClientMissionCleanup) )
{
ClientMissionCleanup.delete();
}
clearClientPaths();

// Terminate all playing sounds
if (isObject(MusicPlayer))
MusicPlayer.stop();

// No longer worried about lag
LagIcon.setVisible(false);

// Dump anything we're not using
purgeResources();


//SHOW CUSTOM LOADING SCREEN OR SOMETHING

schedule(5000,0,"loadNewGameMission",%MapName);
}





function loadNewGameMission(%Map)
{
Canvas.setCursor("DefaultCursor");
echo("~/data/Maps/"@%Map@"/Mission/"@%Map@".mis");
createServer( "SinglePlayer", expandFileName("~/data/Maps/"@%Map@"/Mission/"@%Map@".mis") );
%conn = new GameConnection(ServerConnection);
RootGroup.add(ServerConnection);
%conn.setConnectArgs($pref::Player::Name);
%conn.setJoinPassword($Client::Password);
%conn.connectLocal();

}


This the only solution that I've tried that didnt end up with the engine crashing, me having duplicate ServerConnection.

It looks like i also had to place the loadNewGameMission in a schedule to avoid something like a race condition where if i execute that function too fast i get engine crashes at different locations in the code.

What do you all have to say about this. Is there a better way?

Also I'm looking to see if the 5000 in the schedule can be brought down to something in the milli seconds.

#1
01/16/2009 (3:21 am)
@Kevin - There's no need to destroy the server and have to reconnect back to it again, all you should need to do is call the function loadMission() on the server, it already handles removing the old mission, informing any connected clients and then loading the next mission.
#2
01/17/2009 (10:09 am)
When I call that normally the game crashes and i have no idea why.