In desprate need of some help with Inventory Sorting

Hello,

I am using structures to create Items ans storing them in an array of that structure. An effective Item system that can be used with a gamepad. The issue I am having is inventory stacking. Basically the array would be searched to find duplicates and story the amount of duplicates in an integer while visually making that item appear in the inventory once. Can anyone help me with this? This is the very last piece I need and it’s been beating me up for a month now! Thanks!!

Hello,
If I understand your issue, this is the solution:


Now, to go through what I did:
First, I made an item structure that has two variables; ItemName and ItemCount.
Then I created an event ItemReceived, that would be used to update the player’s inventory whenever he would receive an item from any source(in-game reward, picked up, …).
I then created a variable called wasFound, that would tell us if the player already had that item when we’re done searching his inventory.
Then I used a for each loop to go through all of his items and checked if any of them had the same name as the item we are trying to add to the inventory. If such an item exists, we just add the received number of items to the old number and put the new structure back into it’s old index in the array. If we find an item with the same name, we also set the wasFound variable to true, so we know we already added the items to his inventory. After the loop completes, we check the wasFound variable to see if the items were already added. If the variable is false, it means no items in the player’s inventory matched the item we’re trying to add. In that case, we just add the received item to the end of the array. Notice the mode is set to “Size To fit” because we want the array to expand. Currently, the array’s indexes are 0 to length-1, so we want to write the the index at length to make a new entry.

Hope that helps,
suzi9spal

Thank you so much! It worked with absolutely no issues! I feel bad for not figuring it out myself, I definitely over thought about it and got a completely different result! Because of this my inventory system is completed!