Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Is there a way to put values inside of values inside of a table? (boy was that a mouhtful)

What I want to do is be able to create values inside of a table's value like so:

myTable = {{"Hi",52},{},{}}

label.text = myTable[1][1]
label.Size.X = myTable[1][2]

Is there a way to do something like this in Lua?

1 answer

✓ Accepted answer

This is commonly called a "nested table" e.g. tables inside tables.

Here is a quick example:-

local test = {} -- our main table
local table1 = {1,2,3}
local table2 = {4,5,6}

table.insert(test, table1)
table.insert(test, table2)

-- print the table
for i,v in pairs(test) do
	print(i,v)
end

for i,v in pairs(test) do
	for i2,v2 in pairs(v) do
		print("table", i, "data", v2)
	end
end

Then you should be able to access them like you showed in your code:-

print(test [1][1])

Hope this helps

2 comments

0

I'll give that a 4/5 on rotten tomatoes.

0

i was in a rush :P, ile post a blog then :D

This discussion is preserved as it was. New answers, comments, and votes are closed.