Game Development Community

AIPlayer::onReachDestination()

by Norm Koger · in Torque 3D Professional · 10/12/2009 (7:02 pm) · 3 replies

I have an "AIPlayer" that is moving toward a destination the the empty world level. Upon nearing its destination, as determined in aiPlayer.cpp/AIPlayer::getAIMove(), it invokes the "onReachDestination" callback. This is verified by setting a breakpoint in the line before. Breakpoint trips when aiplayer approaches destination. So far, so good. What I can't figure out is whether any logic is actually being executed in the callback. A breakpoint at aiPlayer.cs function AIPlayer::onReachDestination(%this,%obj), the only defined script function of that name in the full template scripting, is not tripped. The "player" was defined at spawn as spawnclass AIPlayer, using the DefaultPlayerData spawnDataBlock. If not in the aiPlayer.cs, then where do I implement an onReachDestination so that throwCallback() in the cpp code will find it?

About the author

Professional game designer since 1987, with 11 mainstream titles released over the years. M.S. Physics. Software developer for SSI, TalonSoft, and now Storm Eagle Studios.


#1
10/13/2009 (8:44 am)
I was having this problem as well, but then I learned that the AIPlayer never makes callbacks. So instead your code should be
PlayerData::onReachDestination(%this, %obj)
{
}
#2
10/13/2009 (9:47 am)
Just complementing what Bryce said: all Trigger/Player/AIPlayer/StaticShape callbacks are fired on the objects' datablocks, not on themselves. This way you can have different callbacks for different object types. The namespace system allows you to specialize the callbacks in 3 layers. Example:

datablock PlayerData(MyCharacter)
{
   class = "HumanPlayer";   
};
function MyCharacter::onReachDestination(%this, %obj)
{
   echo("AIPlayer" SPC %obj SPC "using datablock" SPC %this.getName() SPC "reached its destination (MyCharacter)!");
   Parent::onReachDestination(%this, %obj);
}
function HumanPlayer::onReachDestination(%this, %obj)
{
   echo("AIPlayer" SPC %obj SPC "using datablock" SPC %this.getName() SPC "reached its destination (HumanPlayer)!");
   Parent::onReachDestination(%this, %obj);
}
function PlayerData::onReachDestination(%this, %obj)
{
   echo("AIPlayer" SPC %obj SPC "using datablock" SPC %this.getName() SPC "reached its destination (PlayerData)!");   
}
The namespace linking system will first call MyCharacter::onReachDestination(). If it doesn't exists, it'll try HumanPlayer::onReachDestination(), and if that doesn't exist either it'll try PlayerData::onReachDestination() (and it will keep going up in the class hierarchy). The "Parent" namespace allows a method to call it's parent's method.
#3
10/13/2009 (4:45 pm)
Hmmm... Thanks for the info, guys.