Is it possible to put a table inside another table

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    well for the table to have a name, cost and a time
  2. What is the issue? Include screenshots / videos if possible!
    well i have the table made, it shows the cost, but I’m trying to make it if i can have a table lets say called table main and then 2 other tables inside, then inside they tables to then have 3 values, 1 being name, 2nd being time, 3rd being the cost, but currently it doesn’t use the time or the name, it just uses the cost of it
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    well i have tried looking around for answers, or similar problems to mine but i haven’t been able to find any as of yet, i am currently still looking .
3 Likes
local tableMain = {
	["item1"] = {["name"] = "", ["time"] = 0, ["cost"] = 0},
	["item2"] = {["name"] = "", ["time"] = 0, ["cost"] = 0}
}
3 Likes

hmm ill give it a go and see how it goes

Yes.

local urtable = {{"meamtableinatable"}}
print(urtable[1][1]) -- meamtableinatable
1 Like
local exTable = {
	item1 = {
		name = "",
		time = 0,
		cost = 0
	},

	item2 = {
		name = "",
		time = 0,
		cost = 0
	}
}

Then you can do

local name1 = exTable.item1.name
local time1 = exTable.item1.time
local cost1 = exTable.item1.cost

Yes, it’s possible to store table references inside other tables. These are called nested tables.

1 Like

Lots of way to do this! Here is one:

local exampleTable = {}
exampleTable['anotherTable'] = {}

-- To insert into this table:
table.insert(exampleTable['anotherTable'], value)
1 Like

Luau tables can be nested infinitely as they’re stored as references. You can even nest a table inside itself.

local t = {}
t[1] = t
print(t[1][1][1][1][1][1][1][1][1]) -- table: 0xf000000
1 Like