[HELP]: Line doesn't execute - 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: [HELP]: Line doesn't execute (
/showthread.php?tid=625940)
[HELP]: Line doesn't execute -
Eoussama - 08.01.2017
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=0; j<sizeof(TDConnect); j++){
PlayerTextDrawHide(playerid, TDConnect[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=0; j<sizeof(TDConnect); j++){
PlayerTextDrawHide(playerid, TDConnect[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!
Re: [HELP]: Line doesn't execute -
Vince - 08.01.2017
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[]).
Re: [HELP]: Line doesn't execute -
SickAttack - 08.01.2017
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!
Re: [HELP]: Line doesn't execute -
Lordzy - 08.01.2017
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.