Creating a table for items in a game

Hey guys,

I was wondering on what is the best way to store all Tools in a table listing their name and values, I was going to use this method but I was unsure whether this was efficient or not or if I should use JSON to list their values, what do you guys suggest?

local itemsingame = {

{name = "Common Sword", rarity = "Common", weight = 50},
{name = "Rare Sword", rarity = "Rare", weight = 25}

}

3 Likes

Correct me if I’m wrong, but that dictionary looks constructed in such a way that it might be kind of hard to get an individual item from it. I’d say you should have the item name as a key, as well as the values.

local itemsInGame = {
    ["Common Sword"] = {
        ["rarity"] = "Common",
        ["weight"] = 50
    },
    ["Rare Sword"] = {
        ["rarity"] = "Rare",
        ["weight"] = 25
    }
}

This is good for easy access of a certain item. e.g. to get the weight of the Common Sword, you would just do
commonWeight = itemsInGame["Common Sword"].weight

1 Like

ah, great. Thanks for the answer!

1 Like

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