Loading seperate level files in T2D.
by torque4a · in Torque Game Builder · 10/03/2006 (4:17 pm) · 6 replies
Hi everyone.
I was wondering if you guys had any pointers on how to load a seperate level file from script?
Currently, I've created a couple of levels in my game, and a very simple menu system. My problem is: about 25% of the time that I tell it to load a level, TGB just crashes. It's real annoying.
Is this the right command that I should be using?
sceneWindow2D.loadLevel(%level);
Where %level is my level file? Yes, I've even tried putting my level name into the function and it still works about 25% of the time.
If there's anything you know that'll help I'd be very grateful.
Thank you.
I was wondering if you guys had any pointers on how to load a seperate level file from script?
Currently, I've created a couple of levels in my game, and a very simple menu system. My problem is: about 25% of the time that I tell it to load a level, TGB just crashes. It's real annoying.
Is this the right command that I should be using?
sceneWindow2D.loadLevel(%level);
Where %level is my level file? Yes, I've even tried putting my level name into the function and it still works about 25% of the time.
If there's anything you know that'll help I'd be very grateful.
Thank you.
About the author
#2
10/03/2006 (10:18 pm)
Also, check out the console.log file after a crash (in the 'games' directory). If there is anything that might shed some light on the problem go ahead and post that aswell. Crashes make us sad. =(
#3
It's complete code is:
Like I said, simple. Next is my console output: Which actually isn't giving anything, but I'll output from when I run it once TGB loads.
I would like to note, that if I load level1.t2d directly from the level builder, it works perfectly, never crashing, etc... But now... when it loads, I get a Windows error and TGB shuts down completely once I tell Windows not to send debug information to Microsoft.
10/04/2006 (6:36 am)
Not a problem, my load function is pretty simple.It's complete code is:
function buttons::onMouseDown(%this, %modifier, %worldPosition, %clicks)
{
if (%this.name $= "Start Level")
sceneWindow2D.loadLevel("game/data/levels/level1.t2d");
}Like I said, simple. Next is my console output: Which actually isn't giving anything, but I'll output from when I run it once TGB loads.
Quote:
Torque Game Builder (v1.1.1) initialized...
Loading compiled script game/main.cs.
Loading compiled script game/managed/datablocks.cs.
Loading compiled script game/managed/persistent.cs.
Loading compiled script game/managed/brushes.cs.
Loading compiled script game/gui/mainScreen.gui.
Loading compiled script game/gameScripts/game.cs.
Loading compiled script game/gameScripts/datablocks.cs.
Loading compiled script game/data/levels/MainMenu.t2d.
Loading compiled script tools/editorClasses/scripts/RSSNews/RSSCache.cs.
Executing game/gameScripts/game.cs.
Executing game/gameScripts/datablocks.cs.
Setting screen mode to 1024x768x32 (w)...
Executing game/gameScripts/mainMenu.cs.
Executing game/gameScripts/design.cs.
Executing game/gameScripts/keyboardFunctions.cs.
Executing game/gameScripts/levelGenerators.cs.
Executing game/gameScripts/levelObjects.cs.
Executing game/gameScripts/globalFunctions.cs.
Executing game/gameScripts/puzzelFunctions.cs.
Executing game/gameScripts/bbStringSprite.cs.
Executing game/data/levels/MainMenu.t2d.
Loading compiled script game/data/levels/level1.t2d.
I would like to note, that if I load level1.t2d directly from the level builder, it works perfectly, never crashing, etc... But now... when it loads, I get a Windows error and TGB shuts down completely once I tell Windows not to send debug information to Microsoft.
#4
sceneWindow2d.schedule(1, "loadlevel", %levelFile);
10/04/2006 (8:32 am)
You have to load the level from within a timer:sceneWindow2d.schedule(1, "loadlevel", %levelFile);
#5
10/04/2006 (10:05 am)
Nick is right. I believe it has something to do with the input callbacks but I'm not positive.
#6
10/04/2006 (2:27 pm)
Ah, that makes sense. The problem is that if the button is in the level that is being unloaded, TGB is trying to delete it to load the next level while the T2D is still executing code on it. That's actually why we neded the safeDelete function, which essentially just schedules an object to be deleted - allowing you to have objects delete themselves. Let us know if the schedule method doesn't work (btw, schedule(0, ...) should work fine).
Torque 3D Owner Matthew Langley
Torque