Hello! I’m working on inventory sorting and I have a button to stack everything in the inventory. So far i have the logic to find the item ID’s for all duplicate slots in the inventory as well as a function that compresses all items together if they are spread out. Now i am just trying to figure out the logic to stack the duplicates into one slot.
I figure it is a pretty straight forward solution, but I hit a wall for some reason. Any suggestions would be great! Here is what I have:
You could try to use a Struct for your items. The Struct will containt your Item class and the number of time the Item is present. Something like that.
So instead of having an Array of Item, you’ll find yourself with an Array of Struct.
If an item is only present once in your inventory, you’ll have a Struct with an occurence of 1. And if it’s present 20 times, you’ll can regroup them in one struct with an Occurence of 20.
This system could also allow you to easily split your eventory and for exemple, split a Struct that contains 20 items into two structs that contains 10 items.