Loading the Next Level in TGB
by JesseL · in Torque Game Builder · 08/28/2007 (11:08 am) · 9 replies
I've gone through a couple of walk-throughs trying to figure out how to load the next level. However, I must be stupid because I keep failing at using the functions that I've learned and commands.
Everytime I try to load a level like level1.t2d I get the error message:
Error loading level ~/data/levels/level1.t2d. Invalid file.
even though its there.
***level.cs***
****player.cs****
Everytime I try to load a level like level1.t2d I get the error message:
Error loading level ~/data/levels/level1.t2d. Invalid file.
even though its there.
***Datablocks.cs***
if(!isObject(LevelEndTimerTemplate)) new t2dSceneObjectDatablock(LevelEndTimerTemplate)
{
class="LevelEndTimerClass";
sceneDuration="10000";
nextLevel="baseLevel.t2d";
};***level.cs***
$basePath = "~/data/levels/";
function LevelEndTimerClass::onLevelLoaded(%this, %scenegraph)
{
%scenegraph.updateList.add(%this);
%this.startTime = %this.getSceneGraph().getSceneTime();
}
function LevelEndTimerClass::onUpdateScene(%this)
{
%currentTime = %this.getSceneGraph().getSceneTime();
%elapsed = mRound((%currentTime - %this.startTime) * 1000);
if (%elapsed >= %this.sceneDuration)
{
%level = $basePath @ %this.nextLevel;
if (isFile( %level ) || isFile( %level @ ".dso"))
sceneWindow2D.schedule(10, loadLevel, %level);
}
}****player.cs****
function LevelEndTimerClass::onLevelLoaded(%this, %scenegraph)
{
echo("Times UP");
%level = $basePath @ %this.nextLevel;
if (isFile( %level ) || isFile( %level @ ".dso"))
sceneWindow2D.schedule(%this.sceneDuration, loadLevel, %level);
}About the author
I just realized that if I wanted to create a cat that caught on fire and ran up a telephone pole and then burst into a blue waterfall. That wouldn't be to hard!
#3
By default the first level loads and plays but after the timer runs out I'd like to load the next level.
Here's where is crashes:
sceneWindow2D.loadLevel("~/data/levels/level2.t2d");
09/16/2007 (5:32 pm)
I have a similar problem. Every time I try to a load a next level the TGB crashes.By default the first level loads and plays but after the timer runs out I'd like to load the next level.
Here's where is crashes:
sceneWindow2D.loadLevel("~/data/levels/level2.t2d");
#4
09/17/2007 (2:05 pm)
CodeDog, please post your console.log file's relevant areas.
#5
09/17/2007 (10:41 pm)
Try scheduling the load, or the funciton that loads, like this.SceneWindow2D.schedule(0, "loadLevel", "~/data/levels/level2.t2d");
#6
As you can see level 1 loads by default just fine but there is no log entry about the TGB crash when loading level 2.
09/17/2007 (11:07 pm)
Console.log//-------------------------- 9/17/2007 -- 22:50:21 -----
Processor Init:
Intel (unknown, Pentium Pro/II/III family), ~2.00 Ghz
(timed at roughly 2.02 Ghz)
FPU detected
MMX detected
SSE detected
Math Init:
Installing Standard C extensions
Installing Assembly extensions
Installing FPU extensions
Installing MMX extensions
Installing SSE extensions
Input Init:
DirectInput enabled.
Initializing chunk mappings...
Could not load this GL function: glGenTextures
Could not load this GL function: glBindTexture
Could not load this GL function: glTexImage2D
Could not load this GL function: glTexParameteri
Could not load this GL function: glTexParameteri
Could not load this GL function: glTexParameteri
Could not load this GL function: glTexParameteri
Could not load this GL function: glGenTextures
Could not load this GL function: glBindTexture
Could not load this GL function: glTexImage2D
Could not load this GL function: glTexParameteri
Could not load this GL function: glTexParameteri
Could not load this GL function: glTexParameteri
Could not load this GL function: glTexParameteri
o 'TEXT' maps to TextChunk
o 'SCHK' maps to UnknownChunk
o 'SCHK' maps to SimChunk
Binding server port to default IP
Debugger connection from 127.0.0.1
Loading compiled script C:/Users/peterson/Documents/MyGames/SmackIt/common/main.cs.
Loading compiled script C:/Users/peterson/Documents/MyGames/SmackIt/game/main.cs.
% - Initializing Common
Loading compiled script C:/Users/peterson/Documents/MyGames/SmackIt/common/preferences/defaultPrefs.cs.
Reading Display Device information...
Primary Display Device Found:
Vendor Id: VEN_0000
Device Id: DEV_0000
Using OpenGL rendering. Fullscreen: 0
Loading compiled script C:/Users/peterson/Documents/MyGames/SmackIt/common/gameScripts/xml.cs.
Loading compiled script C:/Users/peterson/Documents/MyGames/SmackIt/common/gameScripts/properties.cs.
Loading compiled script C:/Users/peterson/Documents/MyGames/SmackIt/common/gameScripts/common.cs.
Loading compiled script C:/Users/peterson/Documents/MyGames/SmackIt/common/gameScripts/audio.cs.
Loading compiled script C:/Users/peterson/Documents/MyGames/SmackIt/common/gameScripts/canvas.cs.
Loading compiled script C:/Users/peterson/Documents/MyGames/SmackIt/common/gameScripts/cursor.cs.
Video Init:
Accelerated OpenGL display device detected.
Accelerated D3D device detected.
Voodoo 2 display device not detected.
Activating the OpenGL display device...
Activating the OpenGL display device...
Setting screen mode to 800x600x32 (w)...
Creating a new window...
Acquiring a new device context...
Pixel format set:
32 color bits, 24 depth bits, 8 stencil bits
Creating a new rendering context...
Making the new rendering context current...
OpenGL driver information:
Vendor: ATI Technologies Inc.
Renderer: ATI MOBILITY RADEON X1800
Version: 2.0.6465 Release
OpenGL Init: Enabled Extensions
ARB_multitexture (Max Texture Units: 8)
EXT_blend_color
EXT_blend_minmax
EXT_compiled_vertex_array
EXT_texture_env_combine
EXT_packed_pixels
EXT_fog_coord
ARB_texture_compression
EXT_texture_compression_s3tc
(ARB|EXT)_texture_env_add
EXT_texture_filter_anisotropic (Max anisotropy: 16)
WGL_EXT_swap_control
OpenGL Init: Disabled Extensions
EXT_paletted_texture
NV_vertex_array_range
3DFX_texture_compression_FXT1
Max Texture Size reported as: 4096
OpenAL Driver Init:
Vendor: Creative Labs Inc.
Version: OpenAL 1.0
Renderer: Software
Extensions: EAX 2.0, EAX 3.0, EAX Unified, and EAX-AC3
Loading compiled script C:/Users/peterson/Documents/MyGames/SmackIt/common/gui/profiles.cs.
Loading compiled script C:/Users/peterson/Documents/MyGames/SmackIt/common/gui/cursors.cs.
Loading compiled script C:/Users/peterson/Documents/MyGames/SmackIt/common/gui/messageBoxOk.gui.
Loading compiled script C:/Users/peterson/Documents/MyGames/SmackIt/common/gui/messageBoxYesNo.gui.
Loading compiled script C:/Users/peterson/Documents/MyGames/SmackIt/common/gui/messageBoxYesNoCancel.gui.
Loading compiled script C:/Users/peterson/Documents/MyGames/SmackIt/common/gui/messageBoxOKCancel.gui.
Loading compiled script C:/Users/peterson/Documents/MyGames/SmackIt/common/gui/messageBoxOKCancelDetailsDlg.gui.
Loading compiled script C:/Users/peterson/Documents/MyGames/SmackIt/common/gui/messagePopup.gui.
Loading compiled script C:/Users/peterson/Documents/MyGames/SmackIt/common/gui/options.gui.
Loading compiled script C:/Users/peterson/Documents/MyGames/SmackIt/common/gui/remap.gui.
Loading compiled script C:/Users/peterson/Documents/MyGames/SmackIt/common/gui/console.gui.
Loading compiled script C:/Users/peterson/Documents/MyGames/SmackIt/common/gui/NetworkMenu.gui.
Loading compiled script C:/Users/peterson/Documents/MyGames/SmackIt/common/gui/startServer.gui.
Loading compiled script C:/Users/peterson/Documents/MyGames/SmackIt/common/gui/joinServer.gui.
Loading compiled script C:/Users/peterson/Documents/MyGames/SmackIt/common/gui/waitingForServer.gui.
Loading compiled script C:/Users/peterson/Documents/MyGames/SmackIt/common/gui/helpDlg.gui.
Loading compiled script C:/Users/peterson/Documents/MyGames/SmackIt/common/gui/messageBox.cs.
Loading compiled script C:/Users/peterson/Documents/MyGames/SmackIt/common/gui/help.cs.
Loading compiled script C:/Users/peterson/Documents/MyGames/SmackIt/common/gui/chatGui.gui.
Loading compiled script C:/Users/peterson/Documents/MyGames/SmackIt/common/gameScripts/screenshot.cs.
Loading compiled script C:/Users/peterson/Documents/MyGames/SmackIt/common/gameScripts/metrics.cs.
Loading compiled script C:/Users/peterson/Documents/MyGames/SmackIt/common/Gui/FrameOverlayGui.gui.
Loading compiled script C:/Users/peterson/Documents/MyGames/SmackIt/common/gameScripts/scriptDoc.cs.
Loading compiled script C:/Users/peterson/Documents/MyGames/SmackIt/common/gameScripts/keybindings.cs.
Loading compiled script C:/Users/peterson/Documents/MyGames/SmackIt/common/gameScripts/options.cs.
Loading compiled script C:/Users/peterson/Documents/MyGames/SmackIt/common/gameScripts/levelManagement.cs.
Loading compiled script C:/Users/peterson/Documents/MyGames/SmackIt/common/gameScripts/projectManagement.cs.
Loading compiled script C:/Users/peterson/Documents/MyGames/SmackIt/common/gameScripts/projectResources.cs.
Loading compiled script C:/Users/peterson/Documents/MyGames/SmackIt/common/gameScripts/align.cs.
Torque Game Builder (v1.5.1) initialized...
Loading compiled script C:/Users/peterson/Documents/MyGames/SmackIt/game/managed/datablocks.cs.
Loading compiled script C:/Users/peterson/Documents/MyGames/SmackIt/game/managed/persistent.cs.
Loading compiled script C:/Users/peterson/Documents/MyGames/SmackIt/game/managed/brushes.cs.
Loading compiled script C:/Users/peterson/Documents/MyGames/SmackIt/game/gameScripts/datablocks.cs.
Loading compiled script C:/Users/peterson/Documents/MyGames/SmackIt/game/gui/mainScreen.gui.
Loading compiled script C:/Users/peterson/Documents/MyGames/SmackIt/game/gameScripts/game.cs.
Loading compiled script C:/Users/peterson/Documents/MyGames/SmackIt/game/gameScripts/mole.cs.
Loading compiled script C:/Users/peterson/Documents/MyGames/SmackIt/game/gameScripts/moleLevel.cs.
Activating DirectInput...
DirectInput joystick failed to enable!
Loading compiled script C:/Users/peterson/Documents/MyGames/SmackIt/game/data/levels/level1.t2d.As you can see level 1 loads by default just fine but there is no log entry about the TGB crash when loading level 2.
#7
This code worked to load the next level.
However, this still doesn't solve the problem of why TGB crashed without an error trap.
There's a missing
09/17/2007 (11:17 pm)
SceneWindow2D.schedule(0, "loadLevel", "game/data/levels/level2.t2d");
This code worked to load the next level.
However, this still doesn't solve the problem of why TGB crashed without an error trap.
There's a missing
try
{
foo();
}
catch(...)
{
cout << "Error: bad things happened\n";
}somewhere
#8
09/18/2007 (7:32 am)
The problem with loading a level is that it immediately deletes the old scene and creates a new one, then returns. But, you're in a function that is referencing something in the deleted, old scene so it crashes. "LoadLevel" is written in script so I suppose it's possible to rewrite the code so that you don't need to schedule it. If someone codes this I've love a copy. I tried once and it failed so I undid the changes and left it alone.
#9
I also tried to get the TGB Reference to be clearer on this issue to avoid these threads, so check that out, though it pretty much says what Nikos just said, if I remember correctly.
Hope that link helps a bit :)
09/18/2007 (9:05 am)
This might be overkill, but I don't have enough time to read through to find the exact problem, but I did a GDC demo that had to load levels. The full scripts were released here, so you can look through and find the level loading code really easily. It was a simple game.I also tried to get the TGB Reference to be clearer on this issue to avoid these threads, so check that out, though it pretty much says what Nikos just said, if I remember correctly.
Hope that link helps a bit :)
Torque 3D Owner Jason Ravencroft