Hello, I am currently working on an Inventory system for my current project, which is using a list to make the removing of items much easier, since I don’t have to update the positions of each item after removal. However, since I’m using a list, this makes dragging items from one slot to another slot that doesn’t already have an existing item incredibly difficult. I’m wondering if it’s possible to add an item to the list at an index that doesn’t currently exist, whilst being able to use (list).add to add items to the list at the indexes before it?
Ya, I’m using a similar system whereby I keep ‘null’ items in the unused slots. I have them referenced in a list for easy addition and removal (in general terms), but I also keep a few functions on the “slots” themselves. I suppose you could move that logic to the main inventory, as well… I just chose this way
To be fair, I can’t remember if I’m using an array or list, but either could work so long as they’re filled entirely by existing spaces (or updated if your list can grow at anytime). Hopefully that makes some sense.
by referenced, I mean to actual game objects (for me , they’re UI elements)
What functions do your slots have?
Well, I think they have things like: drag/drop, set(item, count), adjustslot(count), and updateslot() (which adjusts if you’re showing a stack count > 1 or showing/not showing the item’s image, if there’s one or null).
They also have like pointer enter/exit events for highlighting them.
and they have a few functions to calculate “partial moves”. like if you split a stack of items or something
Brackey’s, on youtube, is doing an rpg tutorial right now and he just covered an inventory system. It’s pretty well thought out so it can be expanded by class extensions.