25.04.2011, 20:03
It's nice. And was it my "GetPlayerWithHighestScore" you've seen? :P (-.-)
However, in my function (GetPlayerWithHighestScore) I use 'cellmin' instead of 0. What is the integer is a '-' value?
Here's an example with your function:
Which will return '0', because:
You see what I mean?
I recommend you to change 'highestyet = 0' to 'highestyet = cellmin', so:
Also, I wouldn't use brackets for one single line after a for statement (optional).
And with the 'new' I would use komma's :P (I'm annoying now aren't I). + why using 'new args = numargs()', you could just use 'numargs' in the loop.
However, sorry for annoying (again :P). But the first thing I've said is quite important for such a function as this.
- Kevin
However, in my function (GetPlayerWithHighestScore) I use 'cellmin' instead of 0. What is the integer is a '-' value?
Here's an example with your function:
pawn Код:
#include <a_samp>
public OnFilterScriptInit()
return printf("%d", GetHighestNumber(-1, -5, -9, -3));
Код:
highestyet = 0; if(-1 > 0) highestyet = -1. FALSE: highestyet stays 0; if(-5 > 0) highestyet = -5. FALSE: highestyet stays 0; if(-9 > 0) highestyet = -9. FALSE: highestyet stays 0; if(-3 > 0) highestyet = -3; FALSE: highestyet stays 0; return highestyet = 0;
I recommend you to change 'highestyet = 0' to 'highestyet = cellmin', so:
pawn Код:
stock GetHighestNumber(...)
{
new args = numargs();
new highestyet = cellmin;
for (new i = 0; i<args; i++)
{
if (getarg(i,0) > highestyet) highestyet = getarg(i,0);
}
return highestyet;
}
pawn Код:
for (new i = 0; i<args; i++)
if (getarg(i,0) > highestyet) highestyet = getarg(i,0);
pawn Код:
stock GetHighestNumber(...)
{
new highestyet = cellmin;
for(new i = 0; i < numargs(); i++)
if(getarg(i) > highestyet) highestyet = getarg(i);
return highestyet;
}
- Kevin