How do I return multiple values in a table

So I’m currently having trouble with getting multiple values from a table. I’m trying to store item descriptions, and rarities in one table but I don’t know how I’ll get both values at once. Any recommendations?

Script:

DescriptionsModule.Descriptions = {
	--<Materials>--
	["Cloth"] = {Description = [[[This could be used to make tools and other materials]], Rarity = "Common"};
	["Cotton"] = {Description = [[Its so sooooooooft!]], Rarity = "Common"};
	["Glass"] = {Description = [[This may come in use in the future]], Rarity = "Common"};

Any help is appreciated!

There are many ways but I would do it by saving a single material to a variable, then indexing this variable for its description and rarity:

local materialInfo = descriptionsModule.Descriptions.Cloth
local description = materialInfo.Description
local rarity = materialInfo.Rarity

If you’re looking to iterate through each material though, you can do something like

for i,v in pairs(descriptionsModule.Descriptions) do
    -- i will be the name of the material, and v will be the material's info for this iteration, which would be something like { Description = 'some string'; Rarity = 'some string' }
    -- then to index it, just do v.entry
    local descriptionThisMaterial = v.Description
    local rarityThisMaterial = v.Rarity
end
2 Likes

You know there will be more than 3 items right. That’ll probably take over 100 lines with the number of items I have in the table.

1 Like

I edited my post, I wasn’t sure if you wanted to iterate through them all or just get the info from a specific material.

i see i’ll try it out and hopefully it’ll work

It worked, tysm for the help! I really appreciate it!

2 Likes

Have you thought about converting your table to a Class? After creating the class, you could make an array of all the items.

Here is a tutorial if you are interested:

1 Like