Problems with playing a level at main menu
by John Steel · in Torque 3D Professional · 12/20/2014 (12:27 am) · 5 replies
Hey everyone, just wondering if anyone could help me out with this issue. I've implemented the displaying a level at the main menu thing from David Wyand's "Torque 3D Game Development Cookbook". I'm pretty sure I've done it all correctly, as it does work. When I launch the game, it displays the splashscreen and then displays the level. The only thing I've changed is having the main menu gui in its own dialog, and using push and popDialog to keep the level displayed as well as any gui I put on top.
Now, to the problem. As I've said, it works fine when I first launch the game. When I either host or join a multiplayer game, the multiplayer game starts fine. When I disconnect from the server, it correctly goes back to the main menu woth the level displayed behind it. However when I start a single player game, when I go to exit the singleplayer game, it disconnects from the game, the splash screen is displayed as if it was loading the main menu, however nothing happens after that. The level for the main menu fails to load. If I just pushed the main menu gui in the console, that shows up over top of where the level would be, so it doesn't jam. Looking in the console, the furthest that it makes it when loading the main menu level is :
CADD: 4996 local
*** Sending mission load to client: mmlevels/MainMenu.mis
Normally when loading a level, it should go:
CADD: 4934 local
*** Sending mission load to client: mmlevels/MainMenu.mis
Mapping string: ServerMessage to index: 0
Mapping string: MsgConnectionError to index: 1
Mapping string: MsgLoadInfo to index: 2
etc...
I looked at where "*** Sending mission load to client: " is, and it seems to be in core/scripts/server/missionDownload.cs. Just before it echoes that it calls commandToClient(%this, 'MissionStartPhase1', $missionSequence, $Server::MissionFile, MissionGroup.musicTrack);, but the echoes that are in that function never run, and so I don't think that function ever runs and I don't know why.
I find it odd why disconnecting a server back to main menu works, but not from a singleplayer game, perhaps there's a variable somewhere messing it up.
Hopefully this was clear enough, and hopefully one of you are able to help me. Apologies for writing so much, just trying to be as clear as possible.
Now, to the problem. As I've said, it works fine when I first launch the game. When I either host or join a multiplayer game, the multiplayer game starts fine. When I disconnect from the server, it correctly goes back to the main menu woth the level displayed behind it. However when I start a single player game, when I go to exit the singleplayer game, it disconnects from the game, the splash screen is displayed as if it was loading the main menu, however nothing happens after that. The level for the main menu fails to load. If I just pushed the main menu gui in the console, that shows up over top of where the level would be, so it doesn't jam. Looking in the console, the furthest that it makes it when loading the main menu level is :
CADD: 4996 local
*** Sending mission load to client: mmlevels/MainMenu.mis
Normally when loading a level, it should go:
CADD: 4934 local
*** Sending mission load to client: mmlevels/MainMenu.mis
Mapping string: ServerMessage to index: 0
Mapping string: MsgConnectionError to index: 1
Mapping string: MsgLoadInfo to index: 2
etc...
I looked at where "*** Sending mission load to client: " is, and it seems to be in core/scripts/server/missionDownload.cs. Just before it echoes that it calls commandToClient(%this, 'MissionStartPhase1', $missionSequence, $Server::MissionFile, MissionGroup.musicTrack);, but the echoes that are in that function never run, and so I don't think that function ever runs and I don't know why.
I find it odd why disconnecting a server back to main menu works, but not from a singleplayer game, perhaps there's a variable somewhere messing it up.
Hopefully this was clear enough, and hopefully one of you are able to help me. Apologies for writing so much, just trying to be as clear as possible.
#2
I did a bit more messing around, and if I just call disconnect() directly in console while in a singleplayer game, it will successfully return to the main menu with the main menu level playing which is good. Still don't understand why leaving the game normally fails to make it work though. I assumed when I pressed escape and selected yes, it would run disconnect() anyway but apparently not. I looked at the gui code for messageBoxYesNoDlg, and when yes is selected, messageBoxYesNoDlg.yesCallback is set, and after a while it gets to eval(%callback) (%callback is just messageBoxYesNoDlg.yesCallback). No idea what happens after that. Is it fine if I change it to just run disconnect() instead? Is that a fine way to leave the game?
12/20/2014 (2:43 pm)
Thanks for the reply Richard, I gave that a go, but unfortunately for some reason all it did was either just extend the time the level would take to get to where it stopped, or the level wouldn't load at all.I did a bit more messing around, and if I just call disconnect() directly in console while in a singleplayer game, it will successfully return to the main menu with the main menu level playing which is good. Still don't understand why leaving the game normally fails to make it work though. I assumed when I pressed escape and selected yes, it would run disconnect() anyway but apparently not. I looked at the gui code for messageBoxYesNoDlg, and when yes is selected, messageBoxYesNoDlg.yesCallback is set, and after a while it gets to eval(%callback) (%callback is just messageBoxYesNoDlg.yesCallback). No idea what happens after that. Is it fine if I change it to just run disconnect() instead? Is that a fine way to leave the game?
#3
12/20/2014 (2:55 pm)
I suppose you could - but it looks like in both cases it goes through disconnect() anyway:// from default.bind.cs:
function escapeFromGame()
{
if ( $Server::ServerType $= "SinglePlayer" )
MessageBoxYesNo( "Exit", "Exit from this Mission?", "disconnect();", "");
else
MessageBoxYesNo( "Disconnect", "Disconnect from the server?", "disconnect();", "");
}
moveMap.bindCmd(keyboard, "escape", "", "handleEscape();");The handleEscape() function is defined in core/scripts/client/core.cs:function handleEscape()
{
if (isObject(EditorGui))
{
if (Canvas.getContent() == EditorGui.getId())
{
EditorGui.handleEscape();
return;
}
else if ( EditorIsDirty() )
{
MessageBoxYesNoCancel( "Level Modified", "Level has been modified in the Editor. Save?",
"EditorDoExitMission(1);",
"EditorDoExitMission();",
"");
return;
}
}
if (isObject(GuiEditor))
{
if (GuiEditor.isAwake())
{
GuiEditCanvas.quit();
return;
}
}
if (PlayGui.isAwake())
escapeFromGame();
}So you hit the escape key, it pops up that dialog when the handleEscape() function figures out you aren't in the editor and calls escapeFromGame(). The escapeFromGame() function then does the same thing whether you're in a multi-player game or not; it calls disconnect():// in scripts/client/serverConnection.cs:
function disconnect()
{
// We need to stop the client side simulation
// else physics resources will not cleanup properly.
physicsStopSimulation( "client" );
// Delete the connection if it's still there.
if (isObject(ServerConnection))
ServerConnection.delete();
disconnectedCleanup();
// Call destroyServer in case we're hosting
destroyServer();
}Now, if this works directly from the console but not from the button then something really strange must be happening. Do you have Torsion? If so you could set a breakpoint in escapeFromGame() and follow the rabbit.
#4
12/20/2014 (4:15 pm)
Finally got it to work! Turns out I had a bit of extra code running when the escape key was pressed in single player. I had ensured that the handleEscape and everything still worked correctly when I had changed it, but perhaps my added code was interfering with it without me realising. I've removed what I thought to be the problem, returning the functions almost identical to what you posted, and it now works as intended. Thank you again for helping me out, I'd spent so much time trying to fix what turned out to be a simple problem. I should definitely look into getting Torsion.
#5
12/21/2014 (7:08 am)
It's really worth it in my opinion - being able to debug scripts in pretty much the same fashion as debugging engine code is incredibly helpful.
Torque Owner Richard Ranft
Roostertail Games