Setting name and animindex of return Actor

Non-platform specific questions.

Setting name and animindex of return Actor

Postby jazz_e_bob » Tue Jul 19, 2005 9:10 am

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?
Controlling complexity is the essence of computer programming.
User avatar
jazz_e_bob
 
Posts: 742
Joined: Tue Jul 01, 2003 9:38 pm
Location: Bloke from Cockatoo Creek Australia
Score: 14 Give a positive score

Postby makslane » Tue Jul 19, 2005 5:08 pm

You can initialize the resultActor:

Actor *resultActor = NULL;

And test for a NULL result when using the function
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

Postby jazz_e_bob » Wed Jul 20, 2005 2:48 am

Thanks mate.

8)
Controlling complexity is the essence of computer programming.
User avatar
jazz_e_bob
 
Posts: 742
Joined: Tue Jul 01, 2003 9:38 pm
Location: Bloke from Cockatoo Creek Australia
Score: 14 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest