Change level
by Rasmus Bach · in Torque Game Builder · 11/14/2011 (5:24 am) · 3 replies
Hello.
I'm trying to make it so when i press a button in my game it will change the level.
This is the script so far:
but when i add the behavior, it wont change lvl
I'm trying to make it so when i press a button in my game it will change the level.
This is the script so far:
if (!isObject(LevelChangerBehavior))
{
%template = new BehaviorTemplate(LevelChangerBehavior);
%template.friendlyName = "Change Level Button";
%template.behaviorType = "Button";
%template.description = "Changes to Level when the image is clicked.";
%template.addBehaviorField(level, "Level to change (.t2d)", string, "Arena");
}
function LevelChangerBehavior::onLevelLoaded(%this)
{
%this.owner.setUseMouseEvents(true);
//allows object to be clicked
}
function LevelChangerBehavior::onMousedown(%this)
{
//the following code line loads the next level with the behavior field
%this.level //note that .t2d is added at the end so we will not have to add the extension in the editor //also the .schedule prevents the engine from crashing, a more detailed explanation can be //found on the Garage Games forum.
sceneWindow2D.schedule(20,"loadLevel", "game/data/levels/" @ %this.level @ ".t2d");
}but when i add the behavior, it wont change lvl
#2
11/14/2011 (11:52 am)
%this.level isn't set to anything in that example.
#3
You getting any errors in the console?
maybe try changing the path to "~/data/levels//"
11/14/2011 (4:11 pm)
did you mean for {
//the following code line loads the next level with the behavior field
%this.level //note that .t2d is added at the end so we will not have to add the extension in the editor //also the .schedule prevents the engine from crashing, a more detailed explanation can be //found on the Garage Games forum.
sceneWindow2D.schedule(20,"loadLevel", "game/data/levels/" @ %this.level @ ".t2d");
}to be {
//the following code line loads the next level with the behavior field %this.level
//note that .t2d is added at the end so we will not have to add the extension in the editor //also the .schedule prevents the engine from crashing, a more detailed explanation can be //found on the Garage Games forum.
sceneWindow2D.schedule(20,"loadLevel", "game/data/levels/" @ %this.level @ ".t2d");
}You getting any errors in the console?
maybe try changing the path to "~/data/levels//"
Torque 3D Owner Christopher Tauscher
Default Studio