Posted 08 June 2015 - 06:32 PM
Today I tried to get information from a table stored in a file. I put the table here: http://pastebin.com/Fi9LsNfk (I pasted it here for convenience)
When I do:
sMats = file.readAll()
print(sMats)
It prints the serialized table as intended, but when I do this:
tMats = textutils.unserialize(sMats)
The unserialization doesn't work and it returns nil. The strange thing is that it works with other tables but not this one. If I recreate the table though the lua console, serialize it, and save it in a file, I get the exact same file, but unserializing the contents works, but if I do a small modification to the file, whatever it is, the string won't unserialize. This is really annoying as I'll want to modify that file often. I really don't understand what's wrong, so I came here for help.
{
stone = {
letter = "#",
color = 256,
},
air = {
letter = "-",
color = 32768,
dord = 0,
},
gold = {
letter = "@",
color = 16,
dord = 5,
},
iron = {
letter = "@",
color = colors.white ,
dord = 15,
},
diamond = {
letter = "*",
color = colors.lightBlue ,
dord = 1,
},
}
When I do:
sMats = file.readAll()
print(sMats)
It prints the serialized table as intended, but when I do this:
tMats = textutils.unserialize(sMats)
The unserialization doesn't work and it returns nil. The strange thing is that it works with other tables but not this one. If I recreate the table though the lua console, serialize it, and save it in a file, I get the exact same file, but unserializing the contents works, but if I do a small modification to the file, whatever it is, the string won't unserialize. This is really annoying as I'll want to modify that file often. I really don't understand what's wrong, so I came here for help.