EndLevel() crashes T2D?
by Gordon C · in Torque Game Builder · 09/15/2006 (11:50 am) · 1 replies
I've been putting together a PoC ("Proof of Concept", but usually "Piece of Crap" also, when I'm at the helm!) with the demo to see if I can do the basics of what I need to do with the TGB. Other than a small gap in the tutorials when it comes to sprites colliding with tilemap layers, it has been an absolute dream come true; a truly wonderful system.
There's just one major issue I can't seem to find a solution to. I can see that there are some forum posts about the issue, but they are inaccessible to me because I haven't purchased TGB yet. The issue is something that is so fundamental to games, that I feel like I must be missing something.
How do I change levels in a game?
I looked through the tutorials, but I only found something on creating a splash screen. I looked through the game.cs and main.cs files, and the logical answer seemed to be: use endGame() followed by startGame("~/path/to/new/level.file"). Or perhaps, call sceneWindow2D.endLevel() and sceneWindow2D.loadLevel(), but when I try to call any of these functions, TGB crashes. There are no error messages other than the generic Windows message: "TGB.exe gas encountered a problem and needs to close".
I've tried calling these methods via schedule, in case TGB wasn't happy with ending the level at that exact moment in the execution, but I get the same result. The related code is below:
So, my question is, is there some other way of changing levels in TGB? Am I going about it all wrong?
I should note, the collision method works fine for other things, so the event isn't the cause of the crash. If I comment out the endGame(); line and replace it with something like updating the player sprite's frame, it works just fine.
Thanks.
There's just one major issue I can't seem to find a solution to. I can see that there are some forum posts about the issue, but they are inaccessible to me because I haven't purchased TGB yet. The issue is something that is so fundamental to games, that I feel like I must be missing something.
How do I change levels in a game?
I looked through the tutorials, but I only found something on creating a splash screen. I looked through the game.cs and main.cs files, and the logical answer seemed to be: use endGame() followed by startGame("~/path/to/new/level.file"). Or perhaps, call sceneWindow2D.endLevel() and sceneWindow2D.loadLevel(), but when I try to call any of these functions, TGB crashes. There are no error messages other than the generic Windows message: "TGB.exe gas encountered a problem and needs to close".
I've tried calling these methods via schedule, in case TGB wasn't happy with ending the level at that exact moment in the execution, but I get the same result. The related code is below:
function EPlayer::onCollision(%srcObj, %dstObj, %srcRef,%dstRef, %time, %normal, %contactCount, %contacts)
{
if ($ThePlayer.gamePaused)
{
return;
}
if (%dstObj.isTrigger && %dstObj.triggerType $= "levelSuccess")
{
$ThePlayer.gamePaused = true;
echo("LOADING NEW LEVEL");
endGame();
// startGame("~/data/levels/poc_dungeon02.t2d");
}
}So, my question is, is there some other way of changing levels in TGB? Am I going about it all wrong?
I should note, the collision method works fine for other things, so the event isn't the cause of the crash. If I comment out the endGame(); line and replace it with something like updating the player sprite's frame, it works just fine.
Thanks.
Associate Charlie Patterson
Default Studio Name
I don't know how to do it correctly yet, but I assume that if you endlevel of endgame within an object, like you did, you will crash. This may be because the object gets deleted as part of cleaning up the scene, then the code returns to it and boom.
Since we are using a dynamic scripting language, I would hope this wouldn't crash the app! A warning would be better.