Jump to content




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


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

#1 whatsfast

  • New Members
  • 35 posts

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?

#2 Kingdaro

    The Doctor

  • Members
  • 1,636 posts
  • Location'MURICA

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


#3 Dlcruz129

    What's a Lua?

  • Members
  • 1,423 posts

Posted 29 November 2012 - 01:51 PM

textutils.serialize(table)


#4 Orwell

    Self-Destructive

  • Members
  • 1,091 posts

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.

#5 ChunLing

  • Members
  • 2,027 posts

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.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users