SA-MP Forums Archive
while loop failing to check statement - 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: while loop failing to check statement (/showthread.php?tid=490266)



while loop failing to check statement - Dr.Einstein - 26.01.2014

In the following code, the while loop fails to assign a value to a variable.

Код:
enum IN
{
rNum,
rVar
};
new lCheck[MAX_PLAYERS][IN];

lCheck[player][rNum] = 0;
while(lCheck[player][rNum] == 0)lCheck[player][rNum] = random(50);
The value of rNum will always be zero. I don't know if this is an issue for me only. The way I got around this is by doing the following.

Код:
new rRock = 0;
while(rRock == 0)rRock = random(50);
lCheck[player][rNum] = rRock;
I know it isn't the end of the world but why would this happen?


Re: while loop failing to check statement - Weponz - 26.01.2014

pawn Код:
while(rRock == 0)rRock = random(50);
This could randomly pick 0, try this:

pawn Код:
while(rRock == 0)rRock = random(50) + 1;
And your issue is common elsewhere, like when you save score it requires you set a variable then save it.


Re: while loop failing to check statement - Dr.Einstein - 26.01.2014

Very foolish of me. I could have just done this:
Код:
 lCheck[player][rNum] = random(50)+1;
Much obliged Weponz.


Re: while loop failing to check statement - Ballu Miaa - 26.01.2014

EDIT: You fixed it while i was writing my post. Testers feel free to delete it.