Game Development Community

onLevelLoaded() for specific level

by Mirko Topalski · in Torque Game Builder · 06/11/2009 (1:37 am) · 9 replies

In my game almost every level is different, and have different functions and victory conditions.
Since, i'll have more than 30 levels, i would like to make new *.cs file for each one.

So, the question is, is there any way for onLevelLoaded() method to execute on specific-level-loaded, or i have to make huge switch-case condition for that event?


#1
06/12/2009 (8:58 am)
I think you should make the switch case or state through variables...

if($currentLevel $= 1)
{
//do wathever you want
}
#2
06/12/2009 (9:15 am)
Yea, i can't find any other solution...

Lots of if-s.
#3
06/12/2009 (10:01 am)
does the generic onLevelLoaded know the name of the mission ?
if so, you could do something like
function onLevelLoaded()
{
   %levelCodeName = "foobar";   // not sure how to get this. in TGE you could use the missionInfo.
   exec("levelScripts/" @ %levelCodeName @ ".cs");
}
#4
06/12/2009 (2:05 pm)
I am trying to set some dynamic field for my t2dSceneGraph, but it always echo a value of "1" no matter what i type in there. :-/
#5
06/13/2009 (7:54 am)
If every level has a name (or the scenegraph has a class) use that. You may have only one scrpit for all the levels using global variables for the persistent stuff and local ones for the specific level stuff.

#6
06/13/2009 (1:58 pm)
Oh yeaaa! Scenegraph can have a class! So i can attach::method() to it.
I have to try that.
Thnx a lot!
#7
06/13/2009 (2:15 pm)
You could also drag a Scene Object into every scene, set its class to something like LevelN and create a *.cs file for every level containing something like

function Level1::onLevelLoaded(%this)
{
   // moo
}

You could then use dynamic fields with these scene objects to set level specific things as well. Example: If you'd create a dynamic field bullets, you could access its content like this:

function Level1::onLevelLoaded(%this)
{
   echo("Bullets for Level1: " @ %this.bullets);
}
#8
06/13/2009 (4:20 pm)
So, basically, you can use onLevelLoaded method on ANY scene object, coz its the method for all scene objects from witch they are all derived, right? (and scenegraph too)
#9
06/13/2009 (10:03 pm)
Quote:So, basically, you can use onLevelLoaded method on ANY scene object
Yes.

Quote:coz its the method for all scene objects from witch they are all derived, right?
onLevelLoaded is a scripted "callback". When a scene is loaded, every scene object is checked for a method onLevelLoaded which then is executed.