Why return 0 here?

I dont really understand why the MaxAcceptable() returns 0 here if the ActionStore contains the index as a key?

 public int MaxAcceptable(InventoryItem item, int index)
        {
            var actionItem = item as ActionItem;
            if (!actionItem) return 0;

            if (dockedItems.ContainsKey(index) && !object.ReferenceEquals(item, dockedItems[index].item))
            {
                return 0;
            }
            if (actionItem.isConsumable())
            {
                return int.MaxValue;
            }
            if (dockedItems.ContainsKey(index))
            {
                return 0;
            }

            return 1;
        }

The last condition before it returns 1, I get the other 2 but the last one does not make sense to me. From my understanding, its checking if the index of the slot exists? If it does exist, why return 0?

It checks how many items are allowed in the slot. If there is an item in the slot, and it’s not a consumable item, it allows 0 items

Yep, in my head I thought that there doesn’t always have to a value assigned to a key in a dictionary but I realised that if there is an index (key) there has to be a value as well (InventoryItem). Thanks!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms