Game Development Community

How do I end the game ?

by Jeff Yaskus · in RTS Starter Kit · 03/02/2010 (3:03 pm) · 4 replies

OK, I set this variable in the global.cs file ... but nowhere does it seem to check for it, to end the mission.

// When a client score reaches this value, the game is ended.
$Game::EndGameScore = 5;

Can anyone explain how this should be working ?

a) where would I add a "check" to see if the players score >= this value ?

b) once detected, how do I properly ... "end the game" ... so it displays the endgame gui, maybe the stats and then returns to main menu ?? or cycles to next map ??

#1
03/03/2010 (10:41 am)
I've found code examples from the starter.FPS and it was using cycleGame() ... after much digging, found there were some functions missing from RTS scripts (that exist in starter.FPS).

Also found that endGame() better meets my needs ... but now there is a problem.

I call endGame() when the score exceeds the "win condition" ... it brings up the end game GUI correctly ... but then crashes because "camera update requested on object that no longer exists".

I'm assuming this means some cleanup is happening -- but not enough (camera updates?) ... triggering these errors.
#2
03/03/2010 (1:20 pm)
more details: when the score is exceeded ... it calls "endGame()" on the server side, which in turn calls the client side "clientCmdEndGame" function.

Here they are for reference ...

server side end game
function endGame()
{
   if (!$Game::Running)  {
      error("endGame: No game running!");
      return;
   }

   // Stop any game timers
   cancel($Game::Schedule);

   // Inform the client the game is over
   for( %clientIndex = 0; %clientIndex < ClientGroup.getCount(); %clientIndex++ ) {
      %cl = ClientGroup.getObject( %clientIndex );
      commandToClient(%cl, 'GameEnd');
   }

   // Delete all the temporary mission objects
   resetMission();
   $Game::Running = false;
}

client side end game code ...
function clientCmdGameEnd(%seq)
{
   // Stop local activity... the game will be destroyed on the server
   alxStopAll();

   // Copy the current scores from the player list into the
   // end game gui (bit of a hack for now).
   EndGameGuiList.clear();
   for (%i = 0; %i < PlayerListGuiList.rowCount(); %i++)
   {
      %text = PlayerListGuiList.getRowText(%i);
      %id = PlayerListGuiList.getRowId(%i);
      EndGameGuiList.addRow(%id,%text);
   }
   EndGameGuiList.sortNumerical(1,false);

   // Display the end-game screen
   Canvas.setContent(EndGameGui);
}

It gets called, pops up the end game GUI (with scores and such) ... and then the game crashes with errors like this in the console.log;
Entering endGame()
   Entering resetMission()
      *** MISSION RESET
      Entering RTSUnitData::onRemove(160, 2662)
      Leaving RTSUnitData::onRemove() - return 2372
...
      Entering RTSUnitData::onRemove(93, 2336)
      Leaving RTSUnitData::onRemove() - return 1609
   Leaving resetMission() - return 
Leaving endGame() - return 
Entering GuiRTSTSCtrl::refreshSelectionDisplay(1348, 1)
Leaving GuiRTSTSCtrl::refreshSelectionDisplay() - return 
Entering GuiRTSTSCtrl::refreshSelectionDisplay(1348, 1)
Leaving GuiRTSTSCtrl::refreshSelectionDisplay() - return 
Received a RTSCameraUpdate for a RTSCamera that isn't ghosted!
Received a RTSCameraUpdate for a RTSCamera that isn't ghosted!
Received a RTSCameraUpdate for a RTSCamera that isn't ghosted!
Received a RTSCameraUpdate for a RTSCamera that isn't ghosted!
Received a RTSCameraUpdate for a RTSCamera that isn't ghosted!
Received a RTSCameraUpdate for a RTSCamera that isn't ghosted!
Mapping string: GameEnd to index: 28
Entering clientCmdGameEnd()
   Entering [CanvasCursor]GuiCanvas::setContent(Canvas, EndGameGui)
      Entering GuiRTSTSCtrl::onSleep(1348)
      Leaving GuiRTSTSCtrl::onSleep() - return 
      Could not locate texture: starter.RTS/client/ui/lobby/disconnect
      Entering EndGameGui::onWake(1257)
      Leaving EndGameGui::onWake() - return 
      Entering [CanvasCursor]GuiCanvas::checkCursor(Canvas)
      Leaving [CanvasCursor]GuiCanvas::checkCursor() - return 1257
   Leaving [CanvasCursor]GuiCanvas::setContent() - return 1257
Leaving clientCmdGameEnd() - return 1257
Entering GuiRTSTSCtrl::refreshSelectionDisplay(1348, 1)
Leaving GuiRTSTSCtrl::refreshSelectionDisplay() - return 
...
Entering GuiRTSTSCtrl::refreshSelectionDisplay(1348, 1)
Leaving GuiRTSTSCtrl::refreshSelectionDisplay() - return 
Received a RTSCameraUpdate for a RTSCamera that isn't ghosted!
Received a RTSCameraUpdate for a RTSCamera that isn't ghosted!
Received a RTSCameraUpdate for a RTSCamera that isn't ghosted!
Received a RTSCameraUpdate for a RTSCamera that isn't ghosted!
Entering GuiRTSTSCtrl::refreshSelectionDisplay(1348, 1)
Leaving GuiRTSTSCtrl::refreshSelectionDisplay() - return 
Entering GuiRTSTSCtrl::refreshSelectionDisplay(1348, 1)
Leaving GuiRTSTSCtrl::refreshSelectionDisplay() - return 
Entering GuiRTSTSCtrl::refreshSelectionDisplay(1348, 1)
Leaving GuiRTSTSCtrl::refreshSelectionDisplay() - return 
Entering GuiRTSTSCtrl::refreshSelectionDisplay(1348, 1)
Leaving GuiRTSTSCtrl::refreshSelectionDisplay() - return 
Fatal: (t:/torque/frts_v3.4/engine/game/rts/rtscamera.cc @ 642) RTSCameraUpdate::pack - someone deleted the RTSCamera out from underneath us!

It looks like the cleanup is happening ... but something to do with camera updates was left running ?

Any ideas how to resolve this -- if no solution soon, I'll need to disable the "endGame" ... so I can turn in my game without crashes.
#3
03/03/2010 (2:55 pm)
Can I propose a naughty hack?

Move the resetMission() call to a serverCmdCleanUp function and call that on the 'OK' button of your endGame GUI.
#4
03/03/2010 (3:46 pm)
I moved it over to the disconnect() function call ... and call cycleGame() instead of endGame() directly.

It loads the end game GUI with no crashes now! thanks

It cuts off the text lines in the process, but hey - good enough for school work.