Y_Iterate - error 017: undefined symbol "Items@YSII_Ag" -
Mado - 18.10.2017
Hi all,
I get this error:
pawn Код:
error 017: undefined symbol "Items@YSII_Ag"
In this piece of code:
pawn Код:
CMD:test(playerid, params[])
{
new str[50], i;
foreach(i : Items)
{
format(str, sizeof(str), "Slot %d - %s %s", i+1, ReturnItemName(i), ReturnItemCondition(i));
print(str);
}
return 1;
}
Enum:
pawn Код:
enum itemInfo{
iID,
iType,
iCondition
};
new ItemInfo[MAX_ITEMS][itemInfo];
I included both the y_iterate include and foreach include, I can't seem to find the problem here. I hope someone else can.
Re: Y_Iterate - error 017: undefined symbol "Items@YSII_Ag" -
VVWVV - 18.10.2017
Could you show how you declared the iterator in the code?
Example:
Re: Y_Iterate - error 017: undefined symbol "Items@YSII_Ag" -
Dayrion - 18.10.2017
PHP код:
new Iterator:Items<MAX_ITEMS>;
Missing this ^
Re: Y_Iterate - error 017: undefined symbol "Items@YSII_Ag" -
Mado - 18.10.2017
Quote:
Originally Posted by VVWVV
Could you show how you declared the iterator in the code?
Example:
|
Not at all, that was the mistake... Thanks anyways!
Quote:
Originally Posted by Dayrion
PHP код:
new Iterator:Items<MAX_ITEMS>;
Missing this ^
|
Thank you!
Re: Y_Iterate - error 017: undefined symbol "Items@YSII_Ag" -
Mado - 18.10.2017
Now I seem to be running in another problem, it doesn't loop trough the items enum at all.
This is my code now, with added prints for debugging purposes:
pawn Код:
new Iterator:Item<MAX_ITEMS>;
CMD:test(playerid, params[])
{
print("/test is called!");
new str[50], i;
foreach(i : Item)
{
printf("print %d", i);
format(str, sizeof(str), "Slot %d - %s %s", i+1, ReturnItemName(i), ReturnItemCondition(i));
print(str);
}
print("loop is finished");
return 1;
}
If I type /test IG I get this in my console:
[23:53:20] /test is called!
[23:53:20] loop is finished
Before running that test code I added a velue to the enum:
pawn Код:
CMD:addinv(playerid, params[])
{
new item, condition, slotid;
if (!IsAdminAuthorized(playerid, 1, 0))
return SendErrorMessage(playerid, "You are not authorized to use this command.");
if (sscanf(params, "ddd", slotid, item, condition))
return SendSyntaxMessage(playerid, "Usage: /addinv [slot] [item] [condition]");
new id = CheckNearestItemSlot();
ItemInfo[id][iID] = id;
ItemInfo[id][iType] = item;
ItemInfo[id][iCondition] = condition;
PlayerInventory[playerid][pInvSlot][slotid] = id;
return 1;
}
Re: Y_Iterate - error 017: undefined symbol "Items@YSII_Ag" -
Dayrion - 18.10.2017
Alriight. You probably don't have what custom iterator does. You should read this carefully :
https://sampforum.blast.hk/showthread.php?tid=570937
Re: Y_Iterate - error 017: undefined symbol "Items@YSII_Ag" -
IllidanS4 - 18.10.2017
From what I understand about y_iterate, shouldn't you be calling
Iter_Add to add something to the iterator? If you don't add something to it, there's nothing to iterate.
Quote:
Originally Posted by Mado
Before running that test code I added a value to the enum
|
You should revise programming terms used in Pawn. You don't "add" a value to enum, an enum is a collection of named constants that can be also used to describe the contents of an array.
But to say something more helpful to you, you are combining two completely unrelated things - you use slot-based inventory to store the item, and then you try to retrieve all items in the inventory using a completely isolated iterator. You should use something akin to this:
Код:
for(new slotid = 0; slotid < sizeof(PlayerInventory[playerid][pInvSlot]); slotid++)
{
new itemid = PlayerInventory[playerid][pInvSlot][slotid];
if(itemid != 0) //if you use 0 for empty slot
{
printf("Slot %d - %s %s", slotid, ReturnItemName(itemid), ReturnItemCondition(itemid));
}
}