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.
%this.owner.removeBehavior(%this); causes the application to crash, but it would be handy for chaining behaviors.
#3
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).
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
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.
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.
Torque Owner Brian Hill