Game Development Community

Problems with AI

by Bristow · in Torque Game Engine · 06/03/2006 (5:10 pm) · 3 replies

Ok so here's my code:


function AIPlayer::searchforplayer(%this)
{
%distance = VectorLen(VectorSub(%this.getTransform(), Cecil.getTransform() ) );


if (%distance <= 20)
{
%this.setMoveDestination(Cecil.getTransform());
echo("close enough");
schedule(1000,0,%this.searchforplayer());
}
else
{
echo("not close enough");
schedule(100,0,%this.searchforplayer());
}
}


All I want it to do is if Cecil (just what I named the player) is within 20 feet run towards him, otherwise basically wait till Cecil is within 20 feet


passing in the name of the AI player seems to work fine for everyhing but schedule, where it crashes



Basically I'm just trying to make a function where if I had more than one enemy in game at a time they could both use this function. The only thing that seems not to work is how I'm using the schedule function, is that the problem?

#1
06/03/2006 (6:01 pm)
Try this instead:
%this.schedule(100,searchforplayer);
#2
06/03/2006 (6:27 pm)
I get:

despair/server/scripts/aiPlayer.cs (292): Unable to find function searchforplayer
#3
06/03/2006 (6:35 pm)
WOW

%this.schedule(100,"searchforplayer");


worked

......which is what you posted aside from the quotation marks , anyway thanks!