Game Development Community

Help with Behavior

by Harrison Brock · in Torque Game Builder · 08/11/2008 (11:22 am) · 4 replies

Here is my code
if (!isObject(HiddenObjectBehavior))
{
   %template = new BehaviorTemplate(HiddenObjectBehavior);
   
   %template.friendlyName = "HiddenObjectBehavior";
   %template.behaviorType = "HiddenObject";
   %template.description  = "Behavior desciption";

// Object will be one of two types 0 being good and 1 being bad
%template.addBehaviorField(ObjType, "The Object Type", float, 0);
}

function HiddenObjectBehavior::onMouseDown(%this, %modifier, %worldPosition, %clicks)
{
   if(%this.ObjType == 1)
   {
      echo("bad object");
      //To Do
      
   }
   
   if(%this.ObjType == 0)
   {
      %this.owner.delete(); // Problem here
   }
}

The thing is when I call %this.owner.delete(); VS 2005 Pro starts trying to debug the .exe for the game. But I don't see any errors at all.

#1
08/11/2008 (11:46 am)
When you delete the owner of the behavior you are also causing the behavior to be destroyed. You can't have a behavior destroy itself from within a callback. Try this,

%this.owner.schedule( 1, delete );
#2
08/11/2008 (12:48 pm)
You should use safeDelete() instead.
#3
08/11/2008 (1:07 pm)
Nice call Phillip '-)
#4
08/12/2008 (11:48 am)
Thanks Philip.

I would have asked you early but I didn't see you online