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"};
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