No integer returned?
#1

Hey all.

I am learning how to make my own checkpoint streamer, yet ran into a problem with this function:

pawn Код:
stock GetPlayerClosestCheckpoint(playerid)
{
    new ClosestCheckpoint;
    new Float:ClosestDistance;
    ClosestDistance=100000000;

    for (new i = 1; i<=MAX_CHECKPOINTS; i++)
    {
        if(CP[i][Created]==1)
        {
            new Float:Distance;
            Distance = GetPlayerDistanceFromPoint(playerid,CP[i][X],CP[i][Y],CP[i][Z]);
            if(Distance<ClosestDistance)
            {
                ClosestDistance=Distance;
                ClosestCheckpoint=i;
            }
        }
    }
    printf("%d",ClosestCheckpoint);
    return ClosestCheckpoint;
}
for some reason, ClosestCheckpoint is not returned (printf doesn't print anything). I can only assume that the function messes up before then for one reason or another.
Reply
#2

Do you not even see an empty print? If you don't, then it's likely that there's a problem with some code in your loop (such as a buffer overflow) which causes the code to crash.

Perhaps your loop goes over the maximum number of checkpoints there are.
Reply
#3

Change

i<=MAX_CHECKPOINTS

to

i<MAX_CHECKPOINTS
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)