Troubles with setting array elem for inventory

Hi everyone,

I’ve been stuck on an issue with my inventory system adding an item to a stack (when the item exists in the inventory).


This is the logic as it stands.

And this is the result.
What I am trying to achieve is increasing the quantity (coloured green) by 1 when an item is added. For some reason, the function adds another row and the amount is set at 2.

I’m wondering what I’m missing to make this function as intended.

You just need to update the quantity element of the struct.

1 Like

Is that not what I’m doing currently?

I do see what you’ve done differently, I’ve made the adjustments, but this is the result; it’s just a new entry with no other data but the adjusted quantity. The quantity has not been added to the existing item.



I’m wondering if it’s because I’m trying to find the item in the array that is equal to the one I am trying to add, but since I am setting the array elem to only account for quantity, that’s why it’s adding a new entry in such a manner.

For updating you definitely need to get the exiting items index in the inventory array. If that doesn’t match then set array element will create a new entry.

Based on your structure you need to Loop the inventory.

Hi,

So, this hasn’t worked.


Pretty much the same result.

somethings broke elsewhere in your code.

I will do some digging. I appreciate your help.

Debug the existing return. Add a print string (Item ID).

It prints the ID, but only once.

As a matter of fact, I got it working.

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