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

term.serialize() and term.unserialize()

Started by cptdeath58, 28 May 2014 - 10:36 PM
cptdeath58 #1
Posted 29 May 2014 - 12:36 AM
What is the term.serialize() and term.unserialize() good for and what do they do?
CometWolf #2
Posted 29 May 2014 - 12:43 AM
term.serialize, is that a 1.6 thing i didn't catch, or do you mean textutils.serialize?
textutils.serialize is used to convert a table to a string, unserialize converts it back.
Edited on 28 May 2014 - 10:43 PM
Lyqyd #3
Posted 29 May 2014 - 12:43 AM
Where are you seeing term.serialize? I only know of textutils.serialize and textutils.unserialize, which are used for turning a table in a string representing the table and vice-versa.
cptdeath58 #4
Posted 29 May 2014 - 12:44 AM
lol my bad textutils.serialize()

[EDIT] Im used to term than textutils
Edited on 28 May 2014 - 10:45 PM
TheOddByte #5
Posted 29 May 2014 - 07:11 PM
textutils.serialize converts a table into a string
It's good when saving a table to a file

local t = { foo = "bar" }
local f = fs.open( "foo-bar", "w" )
f.writeLine( textutils.serialize( t ) )
f.close()
or sending it over rednet

local t = { foo = "bar" }
rednet.send( 101, textutils.serialize( t )
textutils.unserialize converts it back
it's good when loading a serialized table from a file or getting a serialized table over rednet

local f = fs.open( "foo-bar", "r" )
local t = textutils.unserialize( f.readAll() )
f.close()

local id, msg = rednet.receive()
local t = textutils.unserialize( msg )
cptdeath58 #6
Posted 02 June 2014 - 11:08 PM
Thanks, That helps a lot.