Can anyone help me with a mysql error?
#1

Hello, in my script i have moveable doors and they havent been working, and ive been getting a debug from console,
Код:
[20:55:07] [debug] Run time error 4: "Array index out of bounds"
[20:55:07] [debug]  Accessing element at index 4071 past array upper bound 1199
[20:55:07] [debug] AMX backtrace:
[20:55:07] [debug] #0 0016062c in public LoadMoveDoors () at C:\Users\Nick\Desktop\Ingenious!\gamemodes\test2.pwn:19625
here is my code with the error line marked from the debug.

Код:
public LoadMoveDoors()
{
    new rows, fields;
	new total = 0;
	new object, id, model, faction, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz, Float:openspeed, Float:movex, Float:movey, Float:movez, interior, world, name[256];
    cache_get_data(rows, fields);
    if(rows)
    {
		while(total < rows)
		{
			id = cache_get_row_int(total, 0),
			model = cache_get_row_int(total, 1),
			faction = cache_get_row_int(total, 2),
			x = cache_get_row_float(total, 3),
			y = cache_get_row_float(total, 4),
			z = cache_get_row_float(total, 5),
			rx = cache_get_row_float(total, 6),
			ry = cache_get_row_float(total, 7),
			rz = cache_get_row_float(total, 8),
			interior = cache_get_row_int(total, 8),
			world = cache_get_row_int(total, 10),
			cache_get_row(total, 11, name, dbHandle, 128),
			openspeed = cache_get_row_float(total, 12),
			movex = cache_get_row_float(total, 13),
			movey = cache_get_row_float(total, 14),
			movez = cache_get_row_float(total, 15);
			object = CreateDynamicObject(model, x, y, z, rx, ry, rz, world, -1, -1, 200.0);
			Doors[object][doorID] = id;
			Doors[object][doorModel] = model;
			Doors[object][doorFaction] = faction;
			Doors[object][doorPosX] = x;
			Doors[object][doorPosY] = y;
			Doors[object][doorPosZ] = z;
			Doors[object][doorPosRX] = rx;
			Doors[object][doorPosRY] = ry;
			Doors[object][doorPosRZ] = rz;
			Doors[object][doorOpenSpeed] = openspeed;
			Doors[object][doorMoveX] = movex;
			Doors[object][doorMoveY] = movey;
			Doors[object][doorMoveZ] = movez;
			Doors[object][doorInterior] = interior;
			Doors[object][doorVirtualWorld] = world;
			format(Doors[object][doorName], 256, "%s", name); - ERROR LINE
			Doors[object][doorObjectOn] = 1;
			Doors[object][doorObject] = object;
			total++;
		}
    }
	format(msg,sizeof(msg), "Loaded %d dynamic movable doors from MySQL.", total);
	printf(msg);
    return 1;
}
Reply
#2

May i see the Door array?
Код:
new Doors[..
CTRL+F and find "new Doors[" That must be a global variable.
Reply
#3

new engine,lights,alarm,doors,bonnet,boot,objective;

enum MOVEABLE_DOORS
{
doorID,
doorModel,
doorObject,
doorName[256],
doorInterior,
doorVirtualWorld,
doorFaction,
doorOpened,
Float:doorPosX,
Float:doorPosY,
Float:doorPosZ,
Float:doorPosRX,
Float:doorPosRY,
Float:doorPosRZ,
Float:doorOpenSpeed,
Float:doorMoveX,
Float:doorMoveY,
Float:doorMoveZ,
doorObjectOn
}
new MoveDoors[MAX_OBJECTS][MOVEABLE_DOORS];
Reply
#4

<delete>
Reply
#5

Your problem is because you are using the Doors array directly.

I would propose using the below code instead.
Код:
#define MAX_DOORS 500(however may you want to set as a limit)

new DoorsLoaded = 0;
new DoorsInfo[MAX_DOORS][Doors];
and in your code somewhere before you will call the below

Код:
public LoadMoveDoors()
{
    new rows, fields;
	new total = 0;
	new object, id, model, faction, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz, Float:openspeed, Float:movex, Float:movey, Float:movez, interior, world, name[256];
    cache_get_data(rows, fields);
    if(rows)
    {
		while(total < rows)
		{
			id = cache_get_row_int(total, 0),
			model = cache_get_row_int(total, 1),
			faction = cache_get_row_int(total, 2),
			x = cache_get_row_float(total, 3),
			y = cache_get_row_float(total, 4),
			z = cache_get_row_float(total, 5),
			rx = cache_get_row_float(total, 6),
			ry = cache_get_row_float(total, 7),
			rz = cache_get_row_float(total, 8),
			interior = cache_get_row_int(total, 8),
			world = cache_get_row_int(total, 10),
			cache_get_row(total, 11, name, dbHandle, 128),
			openspeed = cache_get_row_float(total, 12),
			movex = cache_get_row_float(total, 13),
			movey = cache_get_row_float(total, 14),
			movez = cache_get_row_float(total, 15);
			object = CreateDynamicObject(model, x, y, z, rx, ry, rz, world, -1, -1, 200.0);
			DoorsInfo[DoorsLoaded][doorID] = id;
			DoorsInfo[DoorsLoaded][doorModel] = model;
			DoorsInfo[DoorsLoaded][doorFaction] = faction;
			DoorsInfo[DoorsLoaded][doorPosX] = x;
			DoorsInfo[DoorsLoaded][doorPosY] = y;
			DoorsInfo[DoorsLoaded][doorPosZ] = z;
			DoorsInfo[DoorsLoaded][doorPosRX] = rx;
			DoorsInfo[DoorsLoaded][doorPosRY] = ry;
			DoorsInfo[DoorsLoaded][doorPosRZ] = rz;
			DoorsInfo[DoorsLoaded][doorOpenSpeed] = openspeed;
			DoorsInfo[DoorsLoaded][doorMoveX] = movex;
			DoorsInfo[DoorsLoaded][doorMoveY] = movey;
			DoorsInfo[DoorsLoaded][doorMoveZ] = movez;
			DoorsInfo[DoorsLoaded][doorInterior] = interior;
			DoorsInfo[DoorsLoaded][doorVirtualWorld] = world;
			format(DoorsInfo[DoorsLoaded][doorName], 256, "%s", name); - ERROR LINE
			DoorsInfo[DoorsLoaded][doorObjectOn] = 1;
			DoorsInfo[DoorsLoaded][doorObject] = object;
			total++;
                        DoorsLoaded++;
		}
    }
	format(msg,sizeof(msg), "Loaded %d dynamic movable doors from MySQL.", DoorsLoaded);
	printf(msg);
    return 1;
}
Then in future if you wanted to find out the index of a DoorsInfo to manage some of the properties or get values etc

Код:
stock GetDoorsInfoIndexByObject(objectid)
{
         for(new i = 0; i < DoorsLoaded; i++)
         {
                 if(DoorsInfo[i][doorObject] == objectid)
                 {
                      return i;
                 }
         }
         return -1;
}


// This could be used like this
new doorindex = GetDoorsInfoIndexByObject(anobjectidyouarehandling);
if(doorindex != -1
{
      DoorsInfo[doorindex][doorInterior] = example;
}
else
{
     // You passed the function an invalid object id
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)