Game Development Community

Load lvl

by Anthony Ratcliffe · in Torque Game Builder · 02/13/2008 (2:43 pm) · 4 replies

I've added a position movement withing my game and when the loop ends i want to change to a diffrent level (scene) however tgb crashes when i use the code below. any help please.





function si::onLevelLoaded(%this)
{
$level = "game/data/levels/end.t2d";
$node=0;

%this.setPositionTarget(48,-30, true, true);
%this.setLinearVelocityX(15);
$node++;
}

//goes along 15

function si::onPositionTarget(%this)
{

if ($node==1)
{
%this.setPositionTarget(48,-28, true, true);
echo ("reached call2");
%this.setLinearVelocityX(0);
%this.setLinearVelocityY(2);
$node++;
}

// code continues to node 36 in the loop



else if ($node==36)
{
echo ("reached call37");

sceneWindow2d.loadLevel ($level);

$node++;
}

#1
02/13/2008 (3:05 pm)
The loadLevel method will delete all of the objects in the scenegraph before loading the new level. The object with the si class is probably getting deleted, and TGB ends up confused because it's still in the process of executing the onPositionTarget method on an object that no longer exists.

Instead, try to schedule the loadLevel instead of calling it directly from an object's method, e.g.:
schedule(0, 0, "DoTransition", %destination);
function DoTransition(%dest)
{
   sceneWindow2D.loadLevel(%dest);
}
#2
02/13/2008 (8:06 pm)
I set up scedule at the top declaring %dest

then set the function below and it came up with scripting errors ?
#3
02/13/2008 (8:32 pm)
Also after using this code i am recieving an error whilst trying to use behaviours

behaviour component::add behaviors missing behaviors ??
#4
02/13/2008 (9:12 pm)
I'm not sure I'm following what you're saying. Can you be more specific about the errors, or post the code?