array sizes do not match, or destination array is too small
#1

Hi. I started working on a new gamemode and now I came to the part where I need to add random loot spawns. What I made is an array with all positions and an array of items which contains items' names, models and whether they can be spawned as loot or not. Here's the function:
Код:
RespawnItems()
{
	new index;
	
	for (new i; i < MAX_ITEMS; i++) if (ItemInfo[i][iModel] && gettime() - ItemInfo[i][iCreateTime] > 900)
		DestroyItem(i);
	
	for (new i; i < sizeof(g_LootSpawns); i++)
	{
		do index = random(sizeof(g_Items));
		while(!g_Items[index][iLootSpawn]);
		
		CreateItem(g_Items[index][iName], g_Items[index][iModel], g_LootSpawns[i][0], g_LootSpawns[i][1], g_LootSpawns[i][2], 0, 0);
	}
	g_LootRespawnTime = 3600;
	
	printf("%d items created.", sizeof(g_LootSpawns));
}
It seems to be absolutely fine for me, but I'm getting this error:
Код:
array sizes do not match, or destination array is too small
on the marked line. The problem seems to be at where I'm getting the random item's name and model here:
Код:
g_Items[index][iName], g_Items[index][iModel]
because when I replace them with something else like "test", 123 it compiles fine.
This is what the array looks like:
Код:
enum e_Items
{
	iName[20],
	iModel,
	iLootSpawn
}
new g_Items[][e_Items] =
{
	{"Sandwich", 2663, true},
	{"Kebar Roll", 2769, true},
        {"Burger", 2768, true}
}
Does anybody spot a mistake here that I don't?
Reply
#2

Hi, it happens when eg
PHP код:
new var[8]; 
format(var, sizeof var, "012345678"); // Array dimensions do no match 
Reply
#3

Код:
enum e_Items
{
    iName[20],
    iModel,
    iLootSpawn
}

static stock
	g_Items[][e_Items] = {
	{"Sandwich", 2663, true},
	{"Kebar Roll", 2769, true},
        {"Burger", 2768, true}
};
Try using it like this. If it doesn't work, it might be something wrong with CreateItem function.
Reply
#4

Have you tried giving your array an exact size?
Код:
new g_Items[3][e_Items] =
{
	{"Sandwich", 2663, true},
	{"Kebar Roll", 2769, true},
        {"Burger", 2768, true}
}
I doubt that this would be the problem, but check it anyways.
Also change iLootSpawn to bool since you are using it as bool.
Код:
enum e_Items
{
	iName[20],
	iModel,
	bool:iLootSpawn
}
Reply
#5

Quote:
Originally Posted by kAn3
Посмотреть сообщение
Hi, it happens when eg
PHP код:
new var[8]; 
format(var, sizeof var, "012345678"); // Array dimensions do no match 
I know and the code you gave wouldn't give an error, it wouldn't just store all of the text in that array.
Quote:
Originally Posted by GloomY
Посмотреть сообщение
Код:
enum e_Items
{
    iName[20],
    iModel,
    iLootSpawn
}

static stock
	g_Items[][e_Items] = {
	{"Sandwich", 2663, true},
	{"Kebar Roll", 2769, true},
        {"Burger", 2768, true}
};
Try using it like this. If it doesn't work, it might be something wrong with CreateItem function.
This is not really how I would use static and stock and CreateItem is fine it works everywhere else.
Quote:
Originally Posted by whadez
Посмотреть сообщение
Have you tried giving your array an exact size?
Код:
new g_Items[3][e_Items] =
{
	{"Sandwich", 2663, true},
	{"Kebar Roll", 2769, true},
        {"Burger", 2768, true}
}
I doubt that this would be the problem, but check it anyways.
Also change iLootSpawn to bool since you are using it as bool.
Код:
enum e_Items
{
	iName[20],
	iModel,
	bool:iLootSpawn
}
I tried giving it a size, but it didn't help and as far as I know it's not needed as the compiler will pick the size itself and I don't like adding the bool tag to variables and it's not really necessary because there's no difference between a boolean and an integer in PAWN, thank you though.
Reply
#6

Quote:
Originally Posted by GoldenLion
Посмотреть сообщение
I know.

This is not really how I would use static and stock and the CreateItem is fine it works everywhere else.

I tried giving it a size, but it didn't help and as far as I know it's unnecessary as the compiler will pick the size itself and I don't like adding the bool tag to variables and it's not really necessary because there's no difference between a boolean and an integer, thank you though.
Well I guess it's up to preference . Could you share only the header of your CreateItem function? Also have you tried to printf all of the values to see if there's any anomaly?
Reply
#7

Quote:
Originally Posted by whadez
Посмотреть сообщение
Well I guess it's up to preference . Could you share only the header of your CreateItem function? Also have you tried to printf all of the values to see if there's any anomaly?
Код:
CreateItem(name[20], model, Float:x, Float:y, Float:z, world, interior)
And yes, I just printed iName and iModel and they are fine.
Reply
#8

Quote:
Originally Posted by GoldenLion
Посмотреть сообщение
Код:
CreateItem(name[20], model, Float:x, Float:y, Float:z, world, interior)
And yes, I just printed iName and iModel and they are fine.
When I create such systems I dont specificy the string's size in the header.
Have you tried actually removing the [20] after name in the header?
Even though you specified 20 char in the enumerator I feel like you should check it just in case.
Reply
#9

Quote:
Originally Posted by GoldenLion
Посмотреть сообщение
I know and the code you gave wouldn't give an error, it wouldn't just store all of the text in that array.
Ofc, my bad. I meant this:
PHP код:
    new var[8]; 
    var = 
"012345678"
Reply
#10

Quote:
Originally Posted by GoldenLion
Посмотреть сообщение
Yes, I tried removing it and I add a size when I want to store the array like this
Код:
ItemInfo[i][iName] = name;
so I don't need to use strcat or format, etc. If I removed the size it would give me that same array sizes don't match error.

EDIT: OK, I removed the size and tried using strcat and now it compiles fine for some reason even though the way I always do it works as well, but not in this case. This is weird.
I'm glad it works.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)