Array index out of bounds
#1

commands were working find until i complied with ysi v4 now they just send SERVER:Unknown command msg and creates the object,
the console:
Code:
[18:18:49] [debug] Run time error 4: "Array index out of bounds"
[18:18:49] [debug]  Attempted to read/write array element at index 1032 in array of size 996
[18:18:49] [debug] AMX backtrace:
[18:18:49] [debug] #0 0001de20 in public cmd_ocreate (2, 347436) in AdminSys.amx
[18:18:49] [debug] #1 native CallLocalFunction () in sampsvr-port_177
[18:18:49] [debug] #2 000006d8 in public OnPlayerCommandText (2, 347380) in AdminSys.amx
Code:
CMD:ocreate(playerid, params[])
{
    if(PlayerInfo[playerid][Level]<3) return SendClientMessage(playerid, COLOR_RED, "SERVER: You're not allowed to use this command");
	new objectid;
    if(sscanf(params,"d", objectid)) return SendClientMessage(playerid,COLOR_RED,"Usage:/ocreate [object id]");
    if(objectid < 321 || objectid > 19999) return SendClientMessage(playerid,COLOR_RED,"SERVER: Object ID not found.");
    {
        objects++;
        objectsid[objects]=objectid;
        new Float:X, Float:Y, Float:Z, str[128];
        GetPlayerPos(playerid, X, Y, Z);
        SpawnedObject[objects] = CreateDynamicObject(objectid, X, Y, Z+1, 0, 0, 0);
		ObjectSpawned[SpawnedObject[objects]] = 1;
		format(str, 128, "SERVER: Object ID: %d - Created at your location - Index: %d", objectid, objects);
		SendClientMessage(playerid, COLOR_RED, str);
    }
    return 1;
}
Reply
#2

Has to be related with ObjectSpawned[SpawnedObject[objects]] or SpawnedObject[objects]. Check array sizes.
Reply
#3

Write ObjectSpawned[SpawnedObject][objects] instead.
Reply
#4

PHP Code:
[18:18:49] [debug]  Attempted to read/write array element at index 1032 in array of size 996 
You tried to read/write at position 1032 in an array sized 996.
Reply
#5

Code:
new SpawnedObject[999];
new ObjectSpawned[999];
still cant find it it was working fine until i got ysi4
Reply
#6

Just increase 999 to higher value. You need at least 1032. It's not even ysi related.
Reply
#7

Quote:
Originally Posted by raydx
View Post
Just increase 999 to higher value. You need at least 1032. It's not even ysi related.
That is not how you fix this type of error.
Reply
#8

Does the script compile fine w/o YSIv4?

Sounds to me like you should try and place some checkpoint prints/clientmessages with the variables in that command, see why you seem to be attempting to read from that inexistent array element.
Reply
#9

I found the line if i remove the line the command works
any ideas what should i do to replace it with something else?
PHP Code:
CMD:ocreate(playeridparams[])
{
    if(
PlayerInfo[playerid][Level]<3) return SendClientMessage(playeridCOLOR_RED"SERVER: You're not allowed to use this command");
    new 
objectid;
    if(
sscanf(params,"d"objectid)) return SendClientMessage(playerid,COLOR_RED,"Usage:/ocreate [object id]");
    if(
objectid 321 || objectid 19999) return SendClientMessage(playerid,COLOR_RED,"SERVER: Object ID not found.");
    {
        
objects++;
        
objectsid[objects]=objectid;
        new 
Float:XFloat:YFloat:Zstr[128];
        
GetPlayerPos(playeridXYZ);
        
SpawnedObject[objects] = CreateDynamicObject(objectidXYZ+1000);
    
ObjectSpawned[SpawnedObject[objects]] = 1//  <-----  this  line
    
format(str128"SERVER: Object ID: %d - Created at your location - Index: %d"objectidobjects);
    
SendClientMessage(playeridCOLOR_REDstr);
    }
    return 
1;

Reply
#10

Quote:
Originally Posted by SaiyanZ
View Post
I found the line if i remove the line the command works
any ideas what should i do to replace it with something else?
PHP Code:
CMD:ocreate(playeridparams[])
{
    if(
PlayerInfo[playerid][Level]<3) return SendClientMessage(playeridCOLOR_RED"SERVER: You're not allowed to use this command");
    new 
objectid;
    if(
sscanf(params,"d"objectid)) return SendClientMessage(playerid,COLOR_RED,"Usage:/ocreate [object id]");
    if(
objectid 321 || objectid 19999) return SendClientMessage(playerid,COLOR_RED,"SERVER: Object ID not found.");
    {
        
objects++;
        
objectsid[objects]=objectid;
        new 
Float:XFloat:YFloat:Zstr[128];
        
GetPlayerPos(playeridXYZ);
        
SpawnedObject[objects] = CreateDynamicObject(objectidXYZ+1000);
    
ObjectSpawned[SpawnedObject[objects]] = 1//  <-----  this  line
    
format(str128"SERVER: Object ID: %d - Created at your location - Index: %d"objectidobjects);
    
SendClientMessage(playeridCOLOR_REDstr);
    }
    return 
1;

Why not try printing the contents of SpawnedObject[objects] into chat or something so you can see what value it has, and then from there figure out how it reaches said value?

The way I understand it, it seems you're giving that variable a value larger than 998, which is why you break out of the array's bounds.
Reply
#11

It will be these two together:

Код:
SpawnedObject[objects] = CreateDynamicObject(objectid, X, Y, Z+1, 0, 0, 0);


    ObjectSpawned[SpawnedObject[objects]] = 1; //  <-----  this  line
CreateDynamicObject returns something over 998, leading to the OOB Markski mentioned.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)