Jump to content




Table in a Table


  • You cannot reply to this topic
3 replies to this topic

#1 FuuuAInfiniteLoop(F.A.I.L)

  • Banned
  • 435 posts
  • LocationThe 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)?

#2 Bubba

    Use Code Tags!

  • Moderators
  • 1,142 posts
  • LocationRHIT

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"


#3 FuuuAInfiniteLoop(F.A.I.L)

  • Banned
  • 435 posts
  • LocationThe left part of this post

Posted 18 March 2013 - 08:52 AM

thanks

#4 SuicidalSTDz

    Permutator of Strings

  • Members
  • 1,308 posts
  • LocationPennsylvania

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






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users