Game Development Community

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().

#1
12/29/2007 (11:56 pm)
So this fix should fix the problem with projectiles firing after the host firing the projectiles is dead correct? I'm a designer and writer so programming lingo only goes so far.
#2
12/30/2007 (2:55 am)
Thanks for sharing this.