I was trying out some things after completing the course, and one problem I have is having multiple parameters for completing the quest. Needing three of the same item to complete it.
I’m not sure how to make this work, the parameter is a string and I was trying to add GetNumberInSlot for the number of the item but it’s an int. Sorry, I don’t know how I can pass that in.
I hadn’t thought to split the predicates between HasItem and HasItems, that’s a good idea.
One other useful thing to add is in the Inventory script. There’s a bool method for HasItems(item), but the methods to determine the quantity of the item won’t give the expected result if the item isn’t stackable. If you don’t want to have to match your item checks to whether the item is stackable, this overload for HasItems is working for me:
/// <summary>
/// Is there an instance of the item in the inventory? If so, return slot.
/// </summary>
public bool HasItem(InventoryItem item, out int slot)
{
for (int i = 0; i < slots.Length; i++)
{
if (object.ReferenceEquals(slots[i].item, item))
{
slot = i;
return true;
}
}
slot = -1;
return false;
}
Then you can use this to check whether you have enough of whatever item:
int slot;
InventoryItem item = InventoryItem.GetFromID(parameterArray[0]);
if (HasItem(item, out slot))
{
if(GetNumberInSlot(slot) < int.Parse(parameters[1]))
{
return false;
}
}
else
{
return false;
}
return true;