Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How to I call a table within a table, and their variables?

Asked by 5 years ago
Edited 5 years ago

So I'm working on a inventory system and I dont know how I can call the tables inside a table and the variables.

Heres the tables in the modulescript I'm trying to call.

local items = {

    ----||Item 1|||----
    {name = "Item1",
    itemid = "000000f",
    itemweight = 0, 
    },
    ----||Item 2|||----
    {name = "Item2",
    itemid = "0000007",
    itemweight = 0, 
    },
    ----||Item 3|||----
    {name = "Item3",
    itemid = "00200FF",
    itemweight = 0, 
    },


}

return items

I only really know how to call Items but not the tables in it, or their variables. How can I do this?

0
Example: print( requiredModule[2].name ) -- Item2 Rare_tendo 3000 — 5y

1 answer

Log in to vote
1
Answered by
jaschutte 324 Moderation Voter
5 years ago

Like this:

local module = require() --your module
local itemInt = 1 --this depends on which item you want to use.

print(module[itemInt]) -- will print out a table,
print(module[itemInt].name) --will print out the name
print(module[itemInt].itemid) --will print out the id
print(module[itemInt].itemweight) --will print out the itemweight.
0
I will try this right away. BlauKitten 88 — 5y
1
This was exactly what I needed! Thank you! BlauKitten 88 — 5y
Ad

Answer this question