SA-MP Forums Archive
'for(new i..)' in another 'for' not working - 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: 'for(new i..)' in another 'for' not working (/showthread.php?tid=655332)



'for(new i..)' in another 'for' not working - Vennox - 18.06.2018

Hi, so i have this code:
PHP код:
new PlayerText:SnakeBox[MAX_PLAYERS][9][9];
public 
OnPlayerConnect(playerid){
    for(new 
i10i++){
        for(new 
u10u++){
            
SnakeBox[playerid][i][u] = CreatePlayerTextDraw(playerid262.327697 13.80011 i194.640869 15.949951 u"box");
            
//other textdraw-releated stuff
            
printf("i = %d, u = %d"iu);
        }
    }
    return 
1;

But in the server console i get this:
Код:
i = 0, u = 0
i = 0, u = 1
i = 0, u = 2
i = 0, u = 3
i = 0, u = 4
i = 0, u = 5
i = 0, u = 6
i = 0, u = 7
i = 0, u = 8
'u' goes from 0 to 8 (it should go to 9) and 'i' remains 0, why?


Re: 'for(new i..)' in another 'for' not working - Pottus - 19.06.2018

Array out of bounds of course.

Код:
new PlayerText:SnakeBox[MAX_PLAYERS][9][9];



Re: 'for(new i..)' in another 'for' not working - Gammix - 19.06.2018

PHP код:
PlayerText:SnakeBox[MAX_PLAYERS][9][9
The limit is set to 9 but you iterate till 10. (PAWN Language works with whole numbers, 0s count)


Re: 'for(new i..)' in another 'for' not working - GTLS - 19.06.2018

What others are trying to say is that, index starts from 0. So if you make an array with size of [9](as in your case), it will go from 0 to 9 spaces more that is, 8. To make it go upto 9, declare the array of size 10.