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

Defining a Table within a Table?

How can I define a table within another table? For Example:

local extable = {90, {3,5}}

print(extable[2, 2])

^ What thats trying to do is print out The 2nd item in the 2nd table inside of extable. It doesnt work and im wondering what the correct method for doing this is?

1 comment

0

Why did you do this instead of using a metatable? http://wiki.roblox.com/index.php?title=Metatable

1 answer

✓ Accepted answer

You defined the table correctly, but to index it you do print(extable[2][2]). It is often a good idea to use string keys if this isn't just an array, like:

local data = {
	Cost = 90,
	MinTime = 3,
	MaxTime = 5,
	RndMsgs = {"Hi there", "Hello"},
}
print(data.Cost) -- 90
print(data.MinTime) --3
print(data.RndMsgs) --table
math.randomseed(tick()) math.random()
print(data.RndMsgs[math.random(1, #data.RndMsgs)]) -- one of RndMsgs

1 comment

0

Thanks! I'll definitely use keys, makes it a whole lot simpler

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