[HELP]: Line doesn't execute
#1

Hello there,
so there is a line which doesn't execute, however when I put it in the beginning, it works,
this is the code:
PHP код:
    for(new j=0j<sizeof(TDConnect); j++){
         
PlayerTextDrawHide(playeridTDConnect[playerid][j]);
    }
    
Kick(playerid); 
well, It tried to debug it and figure out where is the problem, I discovered everything that come after the loop, doesn't execute:
PHP код:

    
for(new j=0j<sizeof(TDConnect); j++){
         
PlayerTextDrawHide(playeridTDConnect[playerid][j]);
     
printf("Textdraw ID: %i was hidden",j);
    }
    
printf("All textdraws were hidden");
    
Kick(playerid);
    
printf("Player Kicked"); 
Console output:
Код:
Textdraw ID: 0 was hidden
Textdraw ID: 1 was hidden
Textdraw ID: 2 was hidden
Textdraw ID: 3 was hidden
Textdraw ID: 4 was hidden
Textdraw ID: 5 was hidden
Textdraw ID: 6 was hidden
Textdraw ID: 7 was hidden
Textdraw ID: 8 was hidden
Textdraw ID: 9 was hidden
Textdraw ID: 10 was hidden
So, what should I do?
Thanks in advance!
Reply
#2

If you use sizeof like that you will get the size of the first dimension, i.e. the one that holds MAX_PLAYERS, and this creates a host of out-of-bounds errors. To get the size of the second dimension use sizeof(TDConnect[]).
Reply
#3

It's due to an array index out of bounds error.

Change:

sizeof(TDConnect)

To:

sizeof(TDConnect[])

And you should be fine.

Edit: The spam machine!
Reply
#4

Because you're getting your arrays out of bounds. It should be : sizeof(TDConnect[]) instead. Consider this example:
pawn Код:
new myarray[10];
new my2darray[15][20];
new my3darray[5][6][7];

sizeof(myarray); //returns 10.
sizeof(my2darray); //returns the first dimension limit : 15
sizeof(my2darray[]); //returns 20.
//similarly...
sizeof(my3darray[][]); //returns 7.
I suppose MAX_PLAYERS as the size of first dimension and it's probably greater than the second of your 2D array. Which is why you looped till MAX_PLAYERS and used higher values as your array index that got you out of bounds.

EDIT : I'm late. It takes me a life time to type when I'm using my mobile.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)