SA-MP Forums Archive
AMX Backtrace - 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: AMX Backtrace (/showthread.php?tid=600150)



AMX Backtrace - KnowNN - 04.02.2016

Hi! I have a problem, i found these errors in my server_log.txt:
Код:
[debug] Run time error 4: "Array index out of bounds"
[debug]  Accessing element at index 48 past array upper bound 47
[debug] AMX backtrace:
[debug] #0 0002d804 in public OnPlayerEnterCheckpoint (playerid=0)
and script problem is:
Код:
new DMVOStep1[49];
Код:
for(new obj = 0; obj < 50; obj++) 
{
    DestroyDynamicObject(DMVOStep1[obj]);
}



Re: AMX Backtrace - KnowNN - 04.02.2016

The problem was
Код:
for(new obj = 0; obj < 50; obj++)
The solving:
Код:
for(new obj = 0; obj < sizeof(DMVOStep1); obj++)
Thanks anyway! ^^


Re: AMX Backtrace - AbyssMorgan - 04.02.2016

PHP код:
for(new obj 0sizeof(DMVOStep1); obj jobj++) 



Re: AMX Backtrace - Yashas - 04.02.2016

Quote:
Originally Posted by AbyssMorgan
Посмотреть сообщение
PHP код:
for(new obj 0sizeof(DMVOStep1); obj jobj++) 
That is wrong.

sizeof is a compile time operator which means the compiler replaces all instances of sizeof with the actual number. So there is no need for one to create an extra variable to store the constant. In fact, the extra variable makes the loop slower since it involves fetching a variable from memory for every iteration.


Re: AMX Backtrace - Abhishek. - 04.02.2016

u array is of 49 elements means 0-48 in index number
a simple fix would be
Код:
for(new obj = 0; obj < 49; obj++)



Re: AMX Backtrace - AmigaBlizzard - 04.02.2016

Or use
PHP код:
new DMVOStep1[50]; 
Then your array will have indices ranging from 0 to 49 (as it has 50 cells).

An array with 49 cells is such a weird number.


Re: AMX Backtrace - Rufio - 04.02.2016

He already solved the issue......