SA-MP Forums Archive
How to make this shorter - 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: How to make this shorter (/showthread.php?tid=491011)



How to make this shorter - ikey07 - 28.01.2014

Im too tired right now, anyone got idea how to make this script abit shorter?

pawn Код:
new id;
if(i == 0 || i == 1) { id = 0; }
else if(i == 2 || i == 3) { id = 1; }
else if(i == 4 || i == 5) { id = 2; }
else if(i == 6 || i == 7) { id = 3; }
else if(i == 8 || i == 9) { id = 4; }
else if(i == 10 || i == 11) { id = 5; }
else if(i == 12 || i == 13) { id = 6; }
else if(i == 14 || i == 15) { id = 7; }
else if(i == 16 || i == 17) { id = 8; }
else if(i == 18 || i == 19) { id = 9; }
else if(i == 20 || i == 21) { id = 10; }
else if(i == 22 || i == 23) { id = 11; }



Re: How to make this shorter - Mauzen - 29.01.2014

You can do that in one very short line.

id = i/2

I guess i is an integer. Dividing one integer by another one will cut off any decimal digits. 6/2=3, 3/2=1, 1/2=0 and so on.


Re: How to make this shorter - ikey07 - 29.01.2014

Didnt though about that, yes, I guess it did so, thanks