This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
whatsfast's profile picture

[Question]How do you turn a table into text.

Started by whatsfast, 29 November 2012 - 12:30 PM
whatsfast #1
Posted 29 November 2012 - 01:30 PM
Whenever I print a table it comes up with table:something. How do I turn the table into text or a string?
Kingdaro #2
Posted 29 November 2012 - 01:34 PM
If you want to print what's in a table, you have to either go through it with a loop,

for i=1, #someTable do
  print(someTable[i])
end

or just use table.concat().

print(table.concat(someTable,', ')) -- prints every part of the table with a comma in between each of them
Dlcruz129 #3
Posted 29 November 2012 - 01:51 PM

textutils.serialize(table)
Orwell #4
Posted 29 November 2012 - 02:39 PM
It the table contains strings and numbers, then Kingdaro's suggestion:

print(table.concat(someTable,',\n'))
and

textutils.tabulate(someTable)
Might be the quickest and cleanest ways to print it readable.
ChunLing #5
Posted 30 November 2012 - 10:01 AM
textutils.serialize is mainly intended for when you need to store/transmit a table (in a file or over rednet), but it can also be useful if you just want the maximum specificity on the layout of the table.