SA-MP Forums Archive
Make cikle back. - 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: Make cikle back. (/showthread.php?tid=497148)



Make cikle back. - audriuxxx - 25.02.2014

Hi,

I want to make cikle when variable is

new DDDRRRUUNNNN[ 20 ];


I want to make cikle from 19 to 0,

Код:
for(new i = 19; i == 0; i --)
But this is not working.


Re: Make cikle back. - Smileys - 25.02.2014

for(new i = 19; i == 0; i --)

what you're doing is:

for( new i = 19; //the variable i has now an integer value of 19;
i == 0; // checking if i is equal to 0, which it isn't because it's 19.
i-- // if i is equal to 0, lower the value with 1.

this will never work, as the variable i, is 19, and it ain't 0, so this will create a never ending loop, because i is always 19, and will never decrease as it only decreases when it's 0.

try this instead:

for( new i = 19; i > 0; i-- )

that checks if i is still above 0, if it is, it'll continue, else it'll stop.


Re: Make cikle back. - Konstantinos - 25.02.2014

That would loop 19 times (19 to 1), but he wants 20 (19 to 0). So it should be:
pawn Код:
for (new i = 19; i >= 0; --i)



Re: Make cikle back. - Smileys - 25.02.2014

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
That would loop 19 times (19 to 1), but he wants 20 (19 to 0). So it should be:
pawn Код:
for (new i = 19; i >= 0; --i)
oh, yea, you're right.

thanks for pointing that out