Best way to use tables in this inventory scenario?

Hello people of the world!


I am about to start on a custom inventory system and I was wondering.
Is this the best way to use tables in this case?
Or is there a more efficient/shorter and easier to read way to do this?

I will have a Gui that displays all the things in the table(InventoryItems) but maybe there is a better way to do this…

Here’s what I mean


--Item Variables
local currentItem = nil
local InventoryItems = {}
local BannedInventoryItems = {}

--I will insert my Items like this
InventoryItems["Block"] = {"Block", 1}

print(InventoryItems)--just to make sure it works (it does)

So is there a better way to get the items in the inventory?
just want to make sure before I start on a big part of my game!


It would suck to finish a large project like this, but then realize that there is a better way to do it…

Feedback?

1 Like

why can’t you just do this?

InventoryItems["Block"] = {1, false}

the false is there to see if it is banned or not, I don’t see the need for a table containing the banned items

good idea.
Thanks for the feedback!

It all depends on what you want the inventory to do. How will you add items? How would you like to display them? Are the items predefined or can people create their own items? All of these questions and more can help you decide how you want to design your project.

As an example, if your inventory will be displayed as a grid system, with drag and drop handling then you might also consider having it as a grid (table of tables) instead of a single table?