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.
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.
About the author
Riding Solo since 2005. Current Project: Fated World 2005-Present RPG Engine Tool Kit - Now available.
Torque Owner Andy Rollins
ZDay Game