Page 1 of 1

Setting name and animindex of return Actor

PostPosted: Tue Jul 19, 2005 9:10 am
by jazz_e_bob
This function returns the closest clone of a particular actor.

Code: Select all
Actor *getClosestClone( char *actorName)
{

  Actor *resultActor;
  Actor *testActor;
  int nClones = 0;
  int index = 1;
  double testDistance;
  double minDistance = 1024;
 
  nClones = ActorCount( actorName );

  while ( index <= nClones )
  {
    testActor = getclone2( actorName, index - 1 );
    testDistance = distance ( x, y , testActor->x, testActor->y );
 
    if ( testDistance < minDistance )
    {
      minDistance = testDistance;
      resultActor = testActor;
    }
 
    index++;
  }

  return resultActor;

}


How do I set this up so it will return Actor if success, invalid Actor (with cloneindex = -1 and name = "invalid Actor") on error?

PostPosted: Tue Jul 19, 2005 5:08 pm
by makslane
You can initialize the resultActor:

Actor *resultActor = NULL;

And test for a NULL result when using the function

PostPosted: Wed Jul 20, 2005 2:48 am
by jazz_e_bob
Thanks mate.

8)