Game Development Community

Ending the game

by Jeff Murray · in Technical Issues · 08/10/2006 (9:08 am) · 8 replies

HelloooO!

I originally posted this in the lighting pack 1.4 forum, but I think it's more to do with the fact that I'm a newb :p so re-posting here to see if you guys have any clues?

This happens in the starter.fps as well as my own game, so I know it's something I'm getting wrong ...

I'm using TLK 1.4 and I seem to be running into a problem restarting my game after game over. Essentially, it just crashes at the lighting stage (just after loading the mission). Please excuse the length of this post .. I'm trying to provide as much info as possible to make it clear ...


First up, the 'try this yourself and let me know if you can stop it from crashing' ...

Quote:

Please feel free to play along at home ;)

I just re-installed TLK 1.4.0 right from the original ZIP file and ran the example (TorqueLightingKit.exe). Selecting the first mission (lighting pack demo), I looked into the swamp (!) then brought up the console to type endgame();

This brought up the end game gui. At this point, the only difference in my game is that I have a button to call Canvas.setContent(mainMenuGui); - so I re-open the console and type it in here instead.

The main menu comes up, then I click start mission and select the first mission (lighting pack demo) again. It crashes soon after (almost immediately this time).


Now, to see what I'm doing in scripts ... (not very much difference between this and the starter.fps) ...

I'm ending the game with endgame();

My endgame script looks like...

function endGame()
{
   if (!$Game::Running)  {
      error("endGame: No game running!");
      return;
   }
   
   // Stop the AIManager
   AIManager.delete();

   // 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;
}

The standard end game script, of course ... the clientCmdGameEnd script looks like this:


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);
}


THEN, my EndGameGui.gui has a button, which sets the canvas to my main menu ...


new GuiButtonCtrl() {
         Profile = "GuiButtonProfile";
         HorizSizing = "right";
         VertSizing = "bottom";
         position = "306 313";
         Extent = "140 30";
         MinExtent = "8 2";
         Visible = "1";
         Command = "Canvas.setContent(mainMenuGui);";
         text = "PLAY AGAIN";
         groupNum = "-1";
         buttonType = "PushButton";
      };

... which seems to work so far. Only problem is, when I click to start the game again it crashes right at the start of the lighting stage.

What could be causing this crash? I've tried this on both my 'dirty' modified version of the engine and a clean install of 1.4 (with clean scripts) ... so it's just got me confused now!

#1
08/10/2006 (9:08 am)
Bob CBuilder said:

Quote:
Ah I didn't realize you were calling endGame directly.

You're mixing two different types of client side processing; endGame is designed to be used during cycleMission processing, it maintains the client connection and then loads a new mission using loadMission. Whereas the mission selection window off of the main menu creates a new server and loads a mission into it.

So when you select a second mission the local client is likely starting up a second server.

You can either create a new or modified mission selection screen that only loads the mission on the existing server (though that won't work on a client/server setup), or fully disconnect the client from the server by calling disconnect() on the client.

I understand that if the server is being created twice, that's a bad thing ... so I set about putting a disconnect(); into the mainmenuGUI.gui onWake. That crashed it. So I tried putting a destroyServer(); instead ... it all ended with a crash.


I just don't understand how this is so complicated! All I want to do is have a single player game with a menu which has a button to play the game (on different missions) then return to the menu after the game over screen ... that's it. As long as it can then re-launch the game on the same mission or different missions, without crashing the engine, that's all I need! What am I missing?! :S


Thanks in advance for any clues/help/suggestions you can give me!!

:)

Jeff.
#2
08/10/2006 (10:01 am)
Maybe try scheduling a destroyServer instead of calling it? I find that frequently in Torque, changes to network state need to be scheduled rather than executed bare, especially when being called inside a clientCmd function (since the clientCmd expects to be able to respond when it's finished).

I don't know for sure that this will help you, but it's worth a try.
#3
08/10/2006 (10:19 am)
Why would you call disconnect() in the mainmenuGUI onWake()? do you want disconnect() to be called when the main menu first pops on the screen?

my advice: put the disconnect() as the last line in your clientCmdGamend().
#4
08/10/2006 (10:32 am)
Thanks for the reply Sean ... is that the way I *should* be ending the game? ie. am I missing a 'cleaner' way of doing it or something?

I'll give that a try now, though :)
#5
08/10/2006 (11:41 am)
Thanks, Cliff and Sean ... scheduling a destroyServer at the game end seems to have done the trick :) Woohoo!

I'd be interested to know how other people deal with ending single player games like this ... any thoughts, anyone?
#6
08/10/2006 (11:42 am)
Jeff in case you didnt know, the onWake() function is called whenever the corresponding gui element is activated. so if you put disconnect() there, then it'll be called whenever the main menu is activated, including when the game first starts. I'm not sure about your implementation which is why I asked you about it, but most likely you don't want disconnect() to be called at the main menu before the first level loads.

ending the game/level can be tricky only because it seems like it should be simple. it is, especially with torque, but you must ensure you do the right things in the right order. in torque, there's distinct differences between loading an initial mission, cycling missions, and unloading the server completely. try to learn the differences between these three and design your guis to call code which mimicks this.
#7
08/10/2006 (12:58 pm)
Thanks again, mister Sean! All is good in my Torque world again ;)

I had assumed that putting the disconnect in the onWake would ensure that it disconnected before making a new connection ... as you said, though, it causes problems because you're always calling it when the game starts.

Another day in Torque, another nifty thing learned!
#8
08/10/2006 (1:16 pm)
Thats good Jeff. as long as it works and doesnt blow up your computer, your doin ok in my book. :)