Bug? StaticShape continuing functions on new level
by Steve Acaster · in Torque 3D Professional · 08/20/2009 (1:27 pm) · 1 replies
If you have a StaticShape which plays a function, especially a scheduled function, and you load a new mission, the scheduled functions keep calling - but can't find the object because they are not in this newly loaded level.
The obvious way to prevent this is for the functions to check that the object exists, and then not do anything if it doesn't. Problem solved.
I was wondering if there was a better way of stopping functions? I noticed that StaticShape doesn't use MissionCleaup.
As I use an onAdd function to start the process, should I be using an onRemove function to end it? Is there an onRemove function and would it be called when loading a new level?
Just on a clean up.
moved to resolved.
The obvious way to prevent this is for the functions to check that the object exists, and then not do anything if it doesn't. Problem solved.
function dofunction1(%this,%obj)
{
if(isObject(%obj))
{
%obj.dosomething1();
%this.schedule(3000,dofunction2, %obj);
}
else
{
//chill
}
function dofunction2(%this,%obj)
{
if(isObject(%obj))
{
%obj.dosomething2();
%this.schedule(3000,dofunction1, %obj);
}
else
{
//chill
}
}I was wondering if there was a better way of stopping functions? I noticed that StaticShape doesn't use MissionCleaup.
As I use an onAdd function to start the process, should I be using an onRemove function to end it? Is there an onRemove function and would it be called when loading a new level?
Just on a clean up.
moved to resolved.
About the author
One Bloke ... In His Bedroom ... Making Indie Games ...
Associate James Ford
Sickhead Games
function MyStaticShapeData::onAdd( %this, %obj ) { %obj.schedule( 3000, update ); } function StaticShape::update( %this ) { // do stuff. %this.schedule( 3000, update ); }Since the schedule is associated with the object, it will be canceled automatically if that object is deleted.
If you need different instances of your StaticShape to update differently, you might need to give them names, and put the update callback within the object-name namespace ( and then probably test isMethod on "update" ) before making the initial schedule ).