Game Development Community

Robot issue

by Tasty Green Pees :-, · in General Discussion · 04/21/2006 (3:39 am) · 3 replies

Hello. I've got a problem with this function. I keep getting this error:

server/scripts/AIPlayer.cs (688): Unable to find object: '' attempting to call function 'getTransform'
server/scripts/AIPlayer.cs (694): Unable to find object: '' attempting to call function 'joinPath'

these are the functions in question (all in AIPlayer.cs):

function AIPlayer::mobility(%this, %bot) {

// "%bot" is the bot in question. "oldposition" is a property set for
// the bot each time through the function so we can measure its progress
// from one iteration to the next.

%botPosition = %bot.getTransform();
%botMovement = vectorDist(%bot.oldposition, %botPosition);
%bot.oldposition = %botPosition;    // ready for the next iteration
if(%botMovement < 2)    // hmm, not moving much
{
   %this.shakeStep(%index);
   %moveBot.joinPath();
} else {    // proceed along the path
   if(isObject(%moveBot.path))
   {
      if (%moveBot.currentNode < 0
         || %moveBot.currentNode > %moveBot.path.getCount())
      {
         %moveBot.currentNode = 1;
      }
      %moveBot.moveToNode(%moveBot.currentNode);
   }
}

%this.schedule(500,"mobility", %obj);
}



// get the bot to shake loose of minor obstacles

function AIPlayer::shakeStep(%this)
{
   %xrand = getRandom(-15,50);
   %yrand = getRandom(-15,45);
   %newLoc = %this.getTransform();

   //adjust the x pos too by 80% of the bots index number
   %newLoc = setWord(%newLoc, 0, (getWord(%newLoc, 0) + (%xrand)));
   %newLoc = setWord(%newLoc, 1, (getWord(%newLoc, 1) + (%yrand)));

   %this.setMoveDestination(%newLoc);
}

// join the closest visible path node

function AIPlayer::joinPath(%this)
{
   if(isObject(%this.path))
   {
      %nodeCount = %this.path.getCount();
      if(%this.currentNode < 0) %this.currentNode = 1;
      
      // check if the selected marker is visible
      if(%this.checkLOSToMarker(%this.path.getObject(%this.currentNode)))
      {
         %this.moveToNode(%this.currentNode);
         return;
      } else {
         // first try a limited range search to be nice to the CPU
         
         if(%this.currentNode + 3 >= %nodeCount) %topNode = %nodeCount - 1;
          else %topNode = %this.currentNode + 3;
         
          for(%i = %topNode; %i >= 0; %i--)
          {
            if(%this.checkLOSToMarker(%this.path.getObject(%i)))
            {
                %this.currentNode = %i;
                %this.moveToNode(%this.currentNode);
               return;
            }
         }
         
         // if were still here its time for a full path search
         
         for(%i = %nodeCount - 1; %i >= 0; %i--)
         {
            if(%this.checkLOSToMarker(%this.path.getObject(%i)))
            {
               %this.currentNode = %i;
               %this.moveToNode(%this.currentNode);
               return;
            }
         }
         
         // if were still here theres problem with the mission layout
         
         echo("mission error - path node visibility error");
      }
   }
   else echo("mission error - no path to follow");
}


// check if the selected path node is visible

function AIPlayer::checkLOSToMarker(%this, %obj)
{
   if(!isObject(%obj)) return false;
   %eyeTrans = %this.getEyePoint();
   %eyeEnd = %obj.getTransform();
   // you may think of other typemasks which represent obstacles
   %searchResult = containerRayCast(%eyeTrans, %eyeEnd,
      $TypeMasks::TerrainObjectType | $TypeMasks::InteriorObjectType, %this);
   %foundObject = firstWord(%searchResult);
   if(!%foundObject) return true;   // path is clear
   else return false;
}

Can anyone help?

#1
04/21/2006 (4:11 am)
Sorry. posted this on the wrong place :^S
#2
04/21/2006 (4:30 am)
I think that the line saying
if(%this.checkLOSToMarker(%this.path.getObject(%this.currentNode)))

Should actually be
if(%this.checkLOSToMarker(%this, %this.path.getObject(%this.currentNode)))

As far as I remember torque should add the this pointer to the beginning but I'm not near a computer with torque so can't verify. This might also hold true for other functions you call.

Though %this.path.getObject(%this.currentNode) might simply just be null, have you verified that?
#3
04/21/2006 (4:32 am)
You should always try echoign all your vars to the console before asking the forum, it might give away any potential errors, check obj before each getTransform... ect, set a breakpoint and use the stacktrace to find the caller and inspect the vars there.