wtf ARRAY?
#1

I have created an array and when i goto retrieve the values from the array, everything works fine until i get to a certain value wtf.

here's the array:
Код:
new Items[][] =
{
{400,520,100,"Landstalker",15},
{424,520,100,"BF Injection",17},
{412,530,100,"Voodoo",23},
{534,530,100,"Remington",34}
};
Then I loop through them and send the client this message for each row on the array(just for testing)
Код:
format(number, sizeof(number),"ID: %d Name: %s Level: %d", Items[idx][0], Items[idx][3], Items[idx][4]);
SendClientMessage(playerid, COLOR_GREEN, number);
Here are messages I get:

Код:
"ID: 400 Name: Landstalker Level 97"
"ID: 424 Name: BF Injection Level 70"
"ID: 412 Name: Voodoo Level 111"
"ID: 534 Name: Remington Level 101"
Everything works correctly until I get to the level part which gives me a value that I have never seen before
Reply
#2

Since you added a string, you must add a third [] for it.

pawn Код:
new Items[][][] =
{
    {400, 520, 100, "Landstalker",  15},
    {424, 520, 100, "BF Injection", 17},
    {412, 530, 100, "Voodoo",       23},
    {534, 530, 100, "Remington",    34}
};
Reply
#3

When i do that it gives me a load of errors:

Код:
error 018: initialization data exceeds declared size
error 052: multi-dimensional arrays must be fully initialized
Reply
#4

I think your best bet would be to create an enum:
pawn Код:
#define MAX_ITEMS    50
enum iInfo
{
    ID,
    Name[32],
    Level
};

new Items[MAX_ITEMS][iInfo];

format(number, sizeof(number),"ID: %d Name: %s Level: %d", Items[idx][ID], Items[idx][Name], Items[idx][Level]);
SendClientMessage(playerid, COLOR_GREEN, number);
Reply
#5

Copy pasting that code into my compiler didn't give me any trouble, show me how did you do yours.
Reply
#6

im not using an enum becuase i have to define the values in the gamemode
Reply
#7

heres the whole array:

Код:
new Items[][][] =
{   
	/////////////Weapons//////////////
	//////////Furniture//////////////////
	{1745,4,10,"Bed",0},
	{2025,4,10,"Dresser",0},
	{2815,4,10,"Rug",0},
	{2566,4,10,"Bed",0},
	{1828,4,10,"Rug",0},
	{2306,4,10,"Table",0},
	{1795,4,10,"Bed",0},
	{2205,4,10,"Desk",0},
	{2133,4,10,"Dresser",0},
	{2134,4,10,"Dresser",0},
	{1726,4,10,"Couch",0},
	{1727,4,10,"chair",0},
	{2311,4,10,"Table",0},
	{2099,4,10,"Stereo",0},
	{2309,4,10,"Chair",0},
	{2565,4,10,"Bed",0},
	{2295,4,10,"Chair",0},
	/////////////Cars///////////////
		//Saloons//
	{401,510,100,"Bravura",0},
	{405,510,100,"Sentinel",0},
		//Offroad//
	{400,520,100,"Landstalker",0},
	{424,520,100,"BF Injection",0},
		//Lowriders//
	{412,530,100,"Voodoo",0},
	{534,530,100,"Remington",0},
		//Sport Cars//
	{402,540,100,"Buffalo",0},
	{411,540,100,"Infernus",0},
		//Industrials//
	{413,550,100,"Pony",0},
	{414,550,100,"Mule",0},
		//Bikes//
	{481,560,30,"BMX",5,19941,0,1327,692,0,0,0,0,0,0,0,0,25,0,2,10,0,0,0,0,0,0,0,0},
	{509,560,30,"Bike",5,19941,0,1327,692,0,0,0,0,0,0,0,0,25,0,2,10,0,0,0,0,0,0,0,0},
	{510,560,30,"Mountain Bike",5,19941,0,1327,692,0,0,0,0,0,0,0,0,25,0,2,10,0,0,0,0,0,0,0,0},
	{448,560,80,"Pizzaboy",8,19941,19917,1327,692,0,0,0,0,0,0,0,0,30,1,2,20,0,0,0,0,0,0,0,0},
	{461,560,80,"PCJ-600",10,19941,19917,1327,692,0,0,0,0,0,0,0,0,35,1,2,25,0,0,0,0,0,0,0,0},
	{462,560,80,"Faggio",8,19941,19917,1327,692,0,0,0,0,0,0,0,0,30,1,2,20,0,0,0,0,0,0,0,0},
	{463,560,80,"Freeway",10,19941,19917,1327,692,0,0,0,0,0,0,0,0,35,1,2,25,0,0,0,0,0,0,0,0},
	{468,560,80,"Sanchez",10,19941,19917,1327,692,0,0,0,0,0,0,0,0,35,1,2,20,0,0,0,0,0,0,0,0},
	{471,560,80,"Quad",15,19941,19917,1327,692,0,0,0,0,0,0,0,0,35,1,2,30,0,0,0,0,0,0,0,0},
	{521,560,80,"FCR-900",15,19941,19917,1327,692,0,0,0,0,0,0,0,0,35,1,2,25,0,0,0,0,0,0,0,0},
	{522,560,80,"NGR-500",30,19941,19917,1327,692,0,0,0,0,0,0,0,0,35,1,2,35,0,0,0,0,0,0,0,0},
	{581,560,80,"BF-400",15,19941,19917,1327,692,0,0,0,0,0,0,0,0,35,1,2,30,0,0,0,0,0,0,0,0},
	{586,560,80,"Wayfarer",10,19941,19917,1327,692,0,0,0,0,0,0,0,0,35,1,2,20,0,0,0,0,0,0,0,0},
		//Boats//
	{446,570,100,"Squallo",0},
	{452,570,100,"Speeder",0},
		//Aircraft//
	{460,580,100,"Skimmer",0},
	{511,580,100,"Beagle",0},
	/////////////ETC////////////////
	{1650,0,5,"Gas Can",0},
	{3409,0,1,"Marijuana",0},
	{2216,0,1,"Snack",0}
};
Reply
#8

Quote:

{481,560,30,"BMX",5,19941,0,1327,692,0,0,0,0,0,0,0 ,0,25,0,2,10,0,0,0,0,0,0,0,0},

Thats a 29 entries.

The one above it is just 5 entries
Quote:

{414,550,100,"Mule",0},

You must equal them, add zeros or something to the less entries one or make another array for the long ones.

pawn Код:
new Items[][][] =
{
    /////////////Weapons//////////////
    //////////Furniture//////////////////
    {1745,4,10,"Bed",0},
    {2025,4,10,"Dresser",0},
    {2815,4,10,"Rug",0},
    {2566,4,10,"Bed",0},
    {1828,4,10,"Rug",0},
    {2306,4,10,"Table",0},
    {1795,4,10,"Bed",0},
    {2205,4,10,"Desk",0},
    {2133,4,10,"Dresser",0},
    {2134,4,10,"Dresser",0},
    {1726,4,10,"Couch",0},
    {1727,4,10,"chair",0},
    {2311,4,10,"Table",0},
    {2099,4,10,"Stereo",0},
    {2309,4,10,"Chair",0},
    {2565,4,10,"Bed",0},
    {2295,4,10,"Chair",0},
    /////////////Cars///////////////
        //Saloons//
    {401,510,100,"Bravura",0},
    {405,510,100,"Sentinel",0},
        //Offroad//
    {400,520,100,"Landstalker",0},
    {424,520,100,"BF Injection",0},
        //Lowriders//
    {412,530,100,"Voodoo",0},
    {534,530,100,"Remington",0},
        //Sport Cars//
    {402,540,100,"Buffalo",0},
    {411,540,100,"Infernus",0},
        //Industrials//
    {413,550,100,"Pony",0},
    {414,550,100,"Mule",0},
        //Bikes//
        //Boats//
    {446,570,100,"Squallo",0},
    {452,570,100,"Speeder",0},
        //Aircraft//
    {460,580,100,"Skimmer",0},
    {511,580,100,"Beagle",0},
    /////////////ETC////////////////
    {1650,0,5,"Gas Can",0},
    {3409,0,1,"Marijuana",0},
    {2216,0,1,"Snack",0}
};

new bikes[][] =
{
    {481,560,30,"BMX",5,19941,0,1327,692,0,0,0,0,0,0,0,0,25,0,2,10,0,0,0,0,0,0,0,0},
    {509,560,30,"Bike",5,19941,0,1327,692,0,0,0,0,0,0,0,0,25,0,2,10,0,0,0,0,0,0,0,0},
    {510,560,30,"Mountain Bike",5,19941,0,1327,692,0,0,0,0,0,0,0,0,25,0,2,10,0,0,0,0,0,0,0,0},
    {448,560,80,"Pizzaboy",8,19941,19917,1327,692,0,0,0,0,0,0,0,0,30,1,2,20,0,0,0,0,0,0,0,0},
    {461,560,80,"PCJ-600",10,19941,19917,1327,692,0,0,0,0,0,0,0,0,35,1,2,25,0,0,0,0,0,0,0,0},
    {462,560,80,"Faggio",8,19941,19917,1327,692,0,0,0,0,0,0,0,0,30,1,2,20,0,0,0,0,0,0,0,0},
    {463,560,80,"Freeway",10,19941,19917,1327,692,0,0,0,0,0,0,0,0,35,1,2,25,0,0,0,0,0,0,0,0},
    {468,560,80,"Sanchez",10,19941,19917,1327,692,0,0,0,0,0,0,0,0,35,1,2,20,0,0,0,0,0,0,0,0},
    {471,560,80,"Quad",15,19941,19917,1327,692,0,0,0,0,0,0,0,0,35,1,2,30,0,0,0,0,0,0,0,0},
    {521,560,80,"FCR-900",15,19941,19917,1327,692,0,0,0,0,0,0,0,0,35,1,2,25,0,0,0,0,0,0,0,0},
    {522,560,80,"NGR-500",30,19941,19917,1327,692,0,0,0,0,0,0,0,0,35,1,2,35,0,0,0,0,0,0,0,0},
    {581,560,80,"BF-400",15,19941,19917,1327,692,0,0,0,0,0,0,0,0,35,1,2,30,0,0,0,0,0,0,0,0},
    {586,560,80,"Wayfarer",10,19941,19917,1327,692,0,0,0,0,0,0,0,0,35,1,2,20,0,0,0,0,0,0,0,0}
};
Reply
#9

ok i fixed that but now im getting this error in my loop

Код:
error 033: array must be indexed (variable "Items")
error 006: must be assigned to an array
Loop:
Код:
stock GetItemType(itemid)
{
    new type;
	for(new idx=1; idx< sizeof(Items); idx++)
	{
	    if(itemid==Items[idx][0])
	    {
	        type=Items[idx][1];
	        break;
	    }
	}
return type;
}
Reply
#10

Umm, try doing it like this ?
pawn Код:
new type;
    for(new idx=1; idx< sizeof(Items); idx++)
    {
        if(itemid == Items[idx][0][0])
        {
            type=Items[idx][1][0];
            break;
        }
    }
    return type;
There should be a better way, maybe you should use enums if your adding a string between them to avoid erros.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)