451 posts
Location
The left part of this post
Posted 18 March 2013 - 08:45 AM
I want to create a table that can be called like table1[table2][table3][name] = value
is that possible? And if its possible, i can serialize and unsrialize that table(because i want to store in a file)?
1190 posts
Location
RHIT
Posted 18 March 2013 - 08:48 AM
Yes and yes. Just make sure that you have defined the table within your table before trying to add values to it.
local myTable = {}
myTable[1] = {}
myTable[2] = {}
myTable[1][1] = "Hello!"
myTable[2][1] = "Test!"
Or a cleaner version:
local myTable = {
["table1"] = {1,2,3,"HELLO!"};
["table2"] = {3,2,1,"Test!!!"};
[3] = {"whatever", 1,2,3};
}
print(myTable.table1[1]) --Outputs 1
print(myTable.table2[4]) --Outputs "Test!!!"
print(myTable[3][1]) --Outputs "whatever"
451 posts
Location
The left part of this post
Posted 18 March 2013 - 08:52 AM
thanks
1511 posts
Location
Pennsylvania
Posted 18 March 2013 - 09:07 AM
table = {
["someTable"] = {
{text = "something here"},
{text = "more things"},
{text = "last thing"}
},
["someOtherTable"] = {
{text = "lols"}
}
}
}
for k,v in pairs(table["someTable"]) do
print(v.text)
end