Page 1 of 1

getClosestClone

PostPosted: Wed Jul 20, 2005 4:51 am
by jazz_e_bob

PostPosted: Fri Jul 22, 2005 10:38 pm
by theta
:D thank you! :D
i tried it and it keeps crashing...
could it be that i'm using the trial version on this computer?
heres what it says when i push spacebar
"Error : Access violation at 0x00510955 (tried to read from 0x000001C1), program terminated."

PostPosted: Sat Jul 23, 2005 3:05 am
by makslane
The space key destroy all "enemy" actors, so the getClosestClone("enemy") don't will get a valid actor and will crash the strcpy function.

Jazz, you can fix this error by creating a "Invalid" actor and return it.
You can make this with this code:

Actor *resultActor = getclone("Invalid.0");

So, when there is no actors to return the initial resultActor will be returned.

PostPosted: Sat Jul 23, 2005 10:20 pm
by brutalDeluxe
This function will fail if clone indexes are non-contiguous. :roll:

PostPosted: Sun Jul 24, 2005 10:32 am
by jazz_e_bob
OK. Thanks for the feedback.

All fixed.

I've included the range on the input of the function. That way you can limit the distance that actors can "see".

Actor *getClosestClone( char *actorName, double range)

http://www.artsystems.com.au/game%20editor/getClosestClone%20DEMO.zip

PostPosted: Wed Jun 28, 2006 8:50 am
by jazz_e_bob
OK - I found another bug.

This one works properly.

Unfortunately it always tests 64 clone indexes. Perhaps there may be a way to fix this in future.

Code: Select all
Actor *getClosestClone( char *actorName, double range)
{
    Actor *resultActor = getclone("invalid.0");
    Actor *testActor;
    int maxClones = 64;
    int i = 0;
    double testDistance;
    double minDistance = range;
 
    while ( i < maxClones )
    {
        testActor = getclone2( actorName, i );
 
        if ( testActor ->cloneindex != -1 )
        {
            testDistance = distance ( x, y , testActor->x, testActor->y );
 
            if ( testDistance < minDistance )
            {
                minDistance = testDistance;
                resultActor = testActor;
            }
        }
 
        i++;
    }

    return resultActor;
}