getClosestClone

Talk about making games.

getClosestClone

Postby jazz_e_bob » Wed Jul 20, 2005 4:51 am

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 theta » Fri Jul 22, 2005 10:38 pm

: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."
theta
 
Posts: 10
Joined: Sat Jul 16, 2005 8:57 pm
Score: 0 Give a positive score

Postby makslane » Sat Jul 23, 2005 3:05 am

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.
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

Postby brutalDeluxe » Sat Jul 23, 2005 10:20 pm

This function will fail if clone indexes are non-contiguous. :roll:
User avatar
brutalDeluxe
 
Posts: 43
Joined: Sun Dec 12, 2004 7:43 am
Score: 0 Give a positive score

Postby jazz_e_bob » Sun Jul 24, 2005 10:32 am

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
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 jazz_e_bob » Wed Jun 28, 2006 8:50 am

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;
}
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 Game Development

Who is online

Users browsing this forum: No registered users and 1 guest