Game Development Community

Cross-Behavior calls

by Alistair Lowe · in Torque Game Builder · 05/10/2010 (3:50 pm) · 1 replies

Hi guys,

I'm attempting to call a function in one behaviour from another but am running into strange issues. I can confirm both behaviours are assigned to trial objects.

On a side note is it possible to inherit/extend behaviors? And if so how?

Here's what I'm attempting:

function AILineOfSight::MoveToward( %this, %that )
{
   %behav = %this.owner.behavior( "AIStates" );
   
   echo( %behav.owner.position.x );

   AIStates::SwitchState( %behav, "Run" );
}

function AIStates::SwitchState( %this, %state )
{

   echo(%this.owner.position.x);

   switch$( %state )
   {
      case "Rest":
         %this.owner.setAnimation( %this.RestAnimation );
      case "Run":
         %this.owner.setAnimation( %this.RunAnimation );
      case "Attack":
         %this.owner.setAnimation( %this.AttackAnimation );
      case "Death":
         %this.owner.setAnimation( %this.DeathAnimation );
   } 
}

Essentially I'm calling AIStates::SwitchState from AILineOfSight::MoveToward and am attempting to ensure I send over the instance of the other behaviour for normal operation. However the echo statement in MoveToward works but the echo statement in SwitchState does not, so something seems to be lost in translation.

I understand I could be doing this completely wrong so would appreciate any help.

Many thanks

#1
05/11/2010 (8:37 am)
That's very odd, as it should work.

More of an aside, but a possible solution, once you have the behavior, you can just do the following "%behav.switchState( "Run" );".