Game Development Community

Restarting a Mission in Torque 3D

by Joshua Allison · in Torque 3D Beginner · 02/18/2010 (12:49 pm) · 6 replies

Hi I am looking for a way to restart a mission in torque 3D. In 1.5 i used loadMyMission() however that function doesnt appear to exsist in torque 3d. I did find a resetMission() burried in the GameCore.cs but using that function has resulted in nothing but failure. What I want to do is


function clientCmdShowVictory(%score)
{
echo("show victory called");
MessageBoxYesNo("You Win!",
"Would you like to restart the game ?",
//Reset code here
quit());
}

I tried
loadMyMission(), // This failed of course with a 'unable to find function loadMyMission
resetMission(), // This failed with a "Unable to find object 'game' attempting to call 'onMissionReset'"
loadMission($server::filename), //This failed at the compiling of the function


I did track down the function resetMission its located at line 145-166 in scripts/server/GameCore.cs and reads as follows
//////////////////////////////////////////////////
function resetMission()
{
//echo("c4 -> resetMission() override success");
echo("*** MISSION RESET");

// Remove any temporary mission objects
//if (isObject(game)){ //Object Showed up here
// echo("Object Exsists");
//}
MissionCleanup.delete();
//if (isObject(game)){ //But not here
// echo("Object Exsists");
//}
$instantGroup = ServerGroup;
new SimGroup(MissionCleanup);
$instantGroup = MissionCleanup;

if (isObject(game))
{
game.deactivatePackages();
game.delete();
game.onMissionReset();
game.onMissionEnded();
}

clearServerpaths();
Game.onMissionReset();
}
/////////////////////////



Any Suggestions? Thanks for your time

#1
02/18/2010 (3:45 pm)
Looks like you've found a bug in the script. onMissionReset and onMissionEnded aren't methods of game, which is why they would break like that. loadMission expects two arguments, the mission to load and a bool for whether it's the first mission or not.

Something to keep in mind with using this method, as the package is deactivated and the game object is deleted, is that everything will have to be loaded again. In a recent project I avoided this by creating my own reset function in which I deleted the NPC's, reset global variables, set the player's transform back to the the spawn point, and respawned the NPC's.

Moved to the Torque 3D forums.
#2
02/19/2010 (2:17 pm)
Im sorry, But i think you are incorrect about that
onMissionReset and onMissionEnded are both defined on lines 309 - 332 as seen below.


function GameCore::onMissionEnded(%game)
{
//echo (%game @"\c4 -> "@ %game.class @" -> GameCore::onMissionEnded");

// Called by endMission(), right before the mission is destroyed

// Normally the game should be ended first before the next
// mission is loaded, this is here in case loadMission has been
// called directly. The mission will be ended if the server
// is destroyed, so we only need to cleanup here.

physicsStopSimulation("server");
%game.endGame();

cancel($Game::Schedule);
$Game::Running = false;
$Game::Cycling = false;
}

function GameCore::onMissionReset(%game)
{
//echo (%game @"\c4 -> "@ %game.class @" -> GameCore::onMissionReset");
%game.startGame();
}

As you can see they are part of GameCore. Any Further suggestions. or perhaps a developer written function to reset a mission.
#3
02/19/2010 (2:55 pm)
Hmm, it's odd that those definitions didn't come up during my find in files search. I'll have to take a look at it again in a couple days when I get back to a computer with the engine installed.
#4
05/04/2010 (10:25 am)
UPDATE:
I never found a restart function However I did find
disconnect(); will return you to the main menu.
#5
11/08/2010 (9:10 pm)
did you ever get this working? I am wanting to set up mission rounds and need the mission reset for each round its played. So I need a reset function call to reset the map before the round starts.
looking to do this in t3d 1.1 b3
#6
11/16/2010 (9:43 pm)
This would be useful, saves having to reload the mission again. I guess you'd need to go through what needs to be reset in the game mission first such as scores etc