Making a loadLevel() function and an onEnter() function
by Bruce Slabinski · in Torque Game Builder · 01/05/2007 (5:09 pm) · 2 replies
Ok I did it and it worked perfectly. Thank you.
About the author
#2
01/24/2007 (11:36 am)
Just as a note, editing your first post to erase what you initially inquired about keeps your post from helping people further down the road that have the same problem. Just post a reply to say thanks so everyone else can benefit from the whole thread.
Torque Owner Brian Hill
function t2dTrigger::onEnter(%this,%obj) { %this.getScenegraph().schedule(100,"loadLevel","pathToLevel"); }...where "pathToLevel" is the relative path to your level file.
%obj holds a reference to the object that entered the trigger but if you load a new level, I think it might delete any objects already in the level first, so it won't be valid after the new level is loaded. Better to store any persistent values, such as score, health, etc, and then reset them in a new player object you create in the 'onLevelLoaded' callback of your scenegraph when the new level is loaded.
The reason you want to call the scenegraph's 'loadLevel' function via schedule, instead of directly, is that you are inside a callback right now. If you load a new level directly, the object that owns the callback method you are in will be deleted while you are still inside it -- this will often make your program fall down and go boom.