SA-MP Forums Archive
Detecting the smallest variables - 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: Detecting the smallest variables (/showthread.php?tid=565413)



Detecting the smallest variables - deimantas1 - 27.02.2015

Hi,

I have like ex that variables:

Quote:

BLABLA[ playerid ][ 0 ] = 113;
BLABLA[ playerid ][ 1 ] = 106;
BLABLA[ playerid ][ 2 ] = 108;
BLABLA[ playerid ][ 3 ] = 110;
BLABLA[ playerid ][ 4 ] = 95;
BLABLA[ playerid ][ 5 ] = 120;
BLABLA[ playerid ][ 6 ] = 125;
BLABLA[ playerid ][ 7 ] = 135;
BLABLA[ playerid ][ 8 ] = 145;
BLABLA[ playerid ][ 9 ] = 155;

How to check which one is smallest?


Re: Detecting the smallest variables - Threshold - 27.02.2015

I'm sure there's an easier way, but the simple way I can think of is:
pawn Код:
new smallvar = 0;
for(new i = 0; i < 10; i++)
{
    if(BLABLA[playerid][i] < BLABLA[playerid][smallvar]) smallvar = i;
}
printf("%d is the smallest value.", BLABLA[playerid][smallvar]);
I think there might be an easy way with y_iterate, but I haven't really used that extensively unfortunately.


Re: Detecting the smallest variables - deimantas1 - 27.02.2015

Thanks, work.