Hey there, I’m putting together an inventory system with my limited knowledge of code and not sure how to get my for loop to behave how i want. I need it to check for slots with the same id as the item i pick up and if that dose not work then check for an empty inventory slot (slot with ID of 0).
`public void AddItem(int itemID, int amount)
{
Debug.Log(“Search”);
for (int i = 0; itemID == slots*.GetComponent<InvSlot>().activeItem || i > slots.Length; i ++)*
{
if(i > slots.Length)
{
for (int x = 0; slots[x].GetComponent().activeItem == 0 || x > slots.Length; x++)
{
slots[x].GetComponent().numItemsHeld += 1;
slots[x].GetComponent().activeItem = itemID;
}
}
else slots*.GetComponent().numItemsHeld += 1;*
break;
}
}`
Im not sure if what im saying makes much sense so any help is appreciated XD.
Thanks in advanced