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

[Lua][Help] How to save a table to file

Started by soccer16x, 17 February 2013 - 07:09 AM
soccer16x #1
Posted 17 February 2013 - 08:09 AM
My question is how would I save a table to a file, so that later i could open that file read it(which i also need help with) and then set the contents of the table to different variable. Could anyone help me out?
diegodan1893 #2
Posted 17 February 2013 - 08:13 AM
you can serialize a table (convert it to a string) and then save it to a file:

--Save table
t = {"1","2","3","4"}
hWrite = fs.open("fileName", "w")
hWrite.write(textutils.serialize(t))
hWrite.close()
--Load the table
hRead = fs.open("fileName", "r")
t = textutils.unserialize(hRead.readLine())
hRead.close()
soccer16x #3
Posted 17 February 2013 - 08:22 AM
Okay thanks for the help, was just unclear on how to go about it.