Game Development Community

T3D 1.1 Preview - Mission timer does not work. - LOGGED (THREED-1719)

by Michael Hall · in Torque 3D Professional · 04/15/2011 (3:13 pm) · 2 replies

Build:
T3D 1.1 Preview and likely the previous Betas as well

Platform:
Any

Target:
The Full Template & FPS Example game scripts.

Issue:
The mission timer that is set to cycle the mission once a certain amount of time has expired is not working.

Repeat:
A global exists in game.cs called $Game::Duration, this is overridden in gameDM.cs (the default gametype if one is stated in the mission file) in function initGameVar(). If you change the value of %game.duration to one minute, the mission will not end after one minute.

Suggest:
To fix the problem, simply go into scripts/server/gameCore.cs, find function startGame() and change this:
// Start the game timer
if ($Game::Duration)
    $Game::Schedule = schedule($Game::Duration * 1000, 0, "onGameDurationEnd");
to:
// Start the game timer
if ($Game::Duration)
    $Game::Schedule = %game.schedule($Game::Duration * 1000, "onGameDurationEnd");// this line changed
Next, in function onGameDurationEnd() you'll have to change it so that it knows the %game variable (which is our gametype script object) as all other functions do. This will allow cycleGame to be properly called once the time limit expires.
function GameCore::onGameDurationEnd(%game) // changed here
{
   //echo (%game @"c4 -> "@ %game.class @" -> GameCore::onGameDurationEnd");

   if ($Game::Duration && !isObject(EditorGui))
      %game.cycleGame(); // changed here
}
Or you can technically just make use of %this argument functionality, the function automatically knows what %this is. I just demonstrated the above changes to make it consistent with the rest of the script.
function GameCore::onGameDurationEnd()  
{  
   //echo (%game @"c4 -> "@ %game.class @" -> GameCore::onGameDurationEnd");  
  
   if ($Game::Duration && !isObject(EditorGui))  
      %this.cycleGame(); // changed here  
}
And lastly, in gameDM.cs (the default gametype if one isn't stated in the mission file) look for function initGameVars() and it has the overridden value for the default $Game::Duration global that was found in game.cs.
// Set the gameplay parameters
%game.duration = 30 * 60; // Change this to affect the time limit.
%game.endgameScore = 20;
%game.endgamePause = 10;
$Game::EndGameScore = 20;
Some thought should probably be given to making this override a bit more flexible/dynamic.


About the author

Been dabbling with game-programming since the age of 10 when I got my first computer, a Commodore. Got serious about game-development after modding Tribes for several years. Doesn't sleep much. Drinks rum. Teaches guitar. Plays cello.


#1
04/21/2011 (3:58 pm)
Logged as THREED-1719.
#2
05/05/2011 (6:23 pm)
Hey Michael, thanks for checking up on this!

I couldn't get all of the code fixes you had to work, so I had to tweak a thing or two. Here's what I've got.

in scripts/server/gameCore.cs, the change i as your suggested.

// Start the game timer
   if ($Game::Duration)
      $Game::Schedule = %game.schedule($Game::Duration * 1000, "onGameDurationEnd"); //<-- Line changed.
   $Game::Running = true;

Though in GameCore::onGameDurationEnd(), I had to make the following change.

function GameCore::onGameDurationEnd()
{
   if ($Game::Duration && (!EditorIsActive() && !GuiEditorIsActive())) //<-- Line changed  
      cycleGame(); //<-- Line unchanged.
}

Adding %game. before cycleGame wasn't working out for me.

That's all I had to do. The duration is still changed in gameDM.cs like you suggested! Thanks for the fix!