Improved Template that Cancels Keybinds
by James Ford · in Torque Game Builder · 08/29/2007 (4:50 pm) · 2 replies
I would like to have a player template object (defined by having a template behavior) and then use clonewithbehaviors to spawn the player, however, I'm noticing a problem or oversight in that, although the original template is not enabled (as a result of the template behavior) other behaviors which bind keys (and are called onbehavioradd) are still getting called, so, when I clonewithbehaviors and spawn the real player, although they keys are rebound, the input still seems to go to the templateplayer object.
Perhaps in templatebehavior.onlevelloaded I can call onbehaviorremove for each other behavior, which would unbind the keys? Yep, answered my own question again, heres the new and improved template behavior:
function TemplateBehavior::onLevelLoaded(%this, %scenegraph)
{
%this.owner.enabled = false;
for(%i=0;%i<%this.owner.getbehaviorcount();%i++)
{
%beh = %this.owner.getbehaviorbyindex(%i);
if (isMethod(%beh.template,"onBehaviorRemove"))
%beh.onbehaviorremove();
}
}
This should work as long as you don't have behaviors doing lots of crazy stuff in onBehaviorRemove().
Perhaps in templatebehavior.onlevelloaded I can call onbehaviorremove for each other behavior, which would unbind the keys? Yep, answered my own question again, heres the new and improved template behavior:
function TemplateBehavior::onLevelLoaded(%this, %scenegraph)
{
%this.owner.enabled = false;
for(%i=0;%i<%this.owner.getbehaviorcount();%i++)
{
%beh = %this.owner.getbehaviorbyindex(%i);
if (isMethod(%beh.template,"onBehaviorRemove"))
%beh.onbehaviorremove();
}
}
This should work as long as you don't have behaviors doing lots of crazy stuff in onBehaviorRemove().
About the author
http://jamesdev.info
Torque Owner Glenn Thomas