No integer returned? - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: No integer returned? (
/showthread.php?tid=349774)
No integer returned? -
burgershot - 10.06.2012
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.
Re: No integer returned? -
Calgon - 10.06.2012
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.
Re: No integer returned? -
MP2 - 10.06.2012
Change
i<=MAX_CHECKPOINTS
to
i<MAX_CHECKPOINTS