'for(new i..)' in another 'for' not working
#1

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?
Reply
#2

Array out of bounds of course.

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

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)
Reply
#4

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)