Game Development Community

Scripted Behavior Removal

by Martin Elliott · in Torque Game Builder · 05/20/2007 (11:45 am) · 4 replies

Is it possible for a behavior to remove itself from it's owner?

%this.owner.removeBehavior(%this); causes the application to crash, but it would be handy for chaining behaviors.

About the author

Recent Threads


#1
05/20/2007 (12:02 pm)
Without looking too deeply at it, I'd try something like this:

%this.owner.schedule(10,removeBehavior,%this);
#2
05/20/2007 (12:34 pm)
Ace, thanks Brian - I didn't think of scheduling...

Cheers,

Martin
#3
05/22/2007 (6:26 pm)
@Martin:

The reason it crashes is that calling %this.owner.removeBehavior() will delete the behavior that is currently executing the script that called it and so pulls the rug out from under itself so to speak and - boom crash.

Perhaps a safeRemoveBehavior() is called for that defers the removal until it is safe to do so (just like safeDelete() for scene objects).
#4
05/23/2007 (2:16 am)
@Neo:

Yeah I thought as much, thanks for clarifying that.

I'm new to TorqueScript but I've worked with custom scripting engines in the past, and whenever a script performed a 'non-trivial' action (Basically anything that could interfere with the architecture side of things, such as scene management or rearranging internals), these were queued for execution at the earliest safe opportunity.