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

Saving and Loading from Text Files

Started by Pyrif, 06 June 2015 - 03:33 AM
Pyrif #1
Posted 06 June 2015 - 05:33 AM
I'm currently working on a program called UPaint which uses a table as a canvas, and I would like to know how I would be able to save that table as a text file and reload it. Thanks in advance! :D/>
Bomb Bloke #2
Posted 06 June 2015 - 06:01 AM
local myTable = {}                           -- Fill this with whatever.
local myFile = fs.open("someFileName", "w")  -- http://www.computercraft.info/wiki/Fs.open
myFile.write(textutils.serialize(myTable))   -- http://www.computercraft.info/wiki/Textutils.serialize
myFile.close()

local myFile = fs.open("someFileName", "r")
local myTable = textutils.unserialize(myFile.readAll())
myFile.close()
Pyrif #3
Posted 06 June 2015 - 06:21 AM
Thank you! I looked through textutils, but I didn't quite get what the default text meant. If I did, I would've gone to the actual textutils.serialize page and looked closer. XD