Array index out of bounds
#1

Since this is really the first time this happened to me, I have no idea how to solve it.

PHP код:
CMD:test(playeridparams[])
{
    new 
string[128];
    
    if(
isnull(params))
        return 
SendClientMessage(playerid, -1"No params");
    
    
format(stringsizeof(string), "TEST: %s (TEST LOCATION: %s)"PlayerName(playerid), zones[player_zone[playerid]][zone_name]);
    
SendClientMessage(playerid, -1string);
    
format(stringsizeof(string), "TEST DESC: %s"params);
    
SendClientMessage(playerid, -1string);
    return 
1;

Код:
[00:57:17] [debug] Run time error 4: "Array index out of bounds"
[00:57:17] [debug]  Accessing element at negative index -1
[00:57:17] [debug] AMX backtrace:
[00:57:17] [debug] #0 0003c1fc in public cmd_test (playerid=0, params[]=@0x00039734 "hsdghsdhgsdg") at C:\xampp\htdocs\samp\gamemodes\wat.pwn:4800
[00:57:17] [debug] #1 native CallLocalFunction () [004743b0] from samp-server.exe
[00:57:17] [debug] #2 000008e0 in public OnPlayerCommandText (playerid=0, cmdtext[]=@0x000396e8 "/test hsdghsdhgsdg") at C:\xampp\htdocs\samp\pawno\include\zcmd.inc:111
Line 4800
PHP код:
format(stringsizeof(string), "TEST: %s (TEST LOCATION: %s)"PlayerName(playerid), zones[player_zone[playerid]][zone_name]); 
If you need anymore (like the zone script) I'll post it.
Reply
#2

The text in black "zones[player_zone[playerid]][zone_name]" contains a superior value to the size of "zones".
Reply
#3

Is there away to even fix that, it just outputs "unknown command". Or is there another way to get a players zone and output it. As of now I'm clueless.
Reply
#4

Quote:
Originally Posted by itsCody
Посмотреть сообщение
Is there away to even fix that, it just outputs "unknown command". Or is there another way to get a players zone and output it. As of now I'm clueless.
It is normal to get the "unknown command" message, after all, that's what you get when you are trying to use an index that is out of bounds on a command.

The fix is pretty obvious, use a value that is inferior to the size of "zones".

For example, you are doing this:
pawn Код:
enum eZones
{
    Float:zones_max_x,
    Float:zones_max_y,
    Float:zones_max_z,
    Float:zones_min_x,
    Float:zones_min_y,
    Float:zones_min_z
};

static const aZones[][eZones] =
{
    {0.0, 0.0, 0.0, 0.0, 0.0, 0.0},
    {0.0, 0.0, 0.0, 0.0, 0.0, 0.0},
    {0.0, 0.0, 0.0, 0.0, 0.0, 0.0},
    {0.0, 0.0, 0.0, 0.0, 0.0, 0.0},
    {0.0, 0.0, 0.0, 0.0, 0.0, 0.0}
};
pawn Код:
aZones[8][zones_max_x]
The array "aZones" can only use the values between 0 and 4, and you are trying to use the value of "zones_max_x" on the 8th row, which isn't possible.
Reply
#5

Ah alright, thanks for the help.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)