Posted 24 July 2017 - 02:16 AM
Hey,
So I am trying to do something like this to save a table in a file:
Then I try and read a file, saving it to an existing table like so:
But when I do so, the tables come up very weirdly..
Notice how it removed the '["' '"]' ONLY in the last one of the first table and the whole second table. Why is it doing this? It is soo weird, and I can't fix it :/
It's like it decided halfway through to ignore strings in tables, however I haven't told it to. Is it a problem with the serialisation?
I have a clue of what it might be..Is it the fact that there is no spaces in the strings so it converts it to a "variable" table title instead? That's very annoying…
I have a clue of what it might be. Is it the fact there is no spaces inbetween words in those strings, so it ignores them as strings and converts to a "variable"?
So I am trying to do something like this to save a table in a file:
local t = {
["Test"] = { 1, 2, 3 },
["Test2"] = { 1, 2, 3 }
}
local tC = {
["button"] = { bg = colors.red, fg = colors.blue },
["test"] = { bg = colors.white, fg = colors.black }
}
local f = fs.open("/test","w")
f.write(textutils.serialise(t))
f.close()
local f2 = fs.open("/colours","w")
f.write(textutils.serialise(tC))
f.close()
Then I try and read a file, saving it to an existing table like so:
local t = {}
local f = fs.open("/test","r")
t = textutils.unserialise(f.readAll())
f.close()
But when I do so, the tables come up very weirdly..
-- This is the results of loading the tables (keep in mind this is also what it looks like in the file that the table was saved to)
local t = {
[ "Test" ] = { 1, 2, 3 },
Test2 = { 1, 2, 3 }
}
local tC = {
button = { bg = colors.red, fg = colors.blue },
test = { bg = colors.white, fg = colors.black }
}
Notice how it removed the '["' '"]' ONLY in the last one of the first table and the whole second table. Why is it doing this? It is soo weird, and I can't fix it :/
It's like it decided halfway through to ignore strings in tables, however I haven't told it to. Is it a problem with the serialisation?
I have a clue of what it might be..Is it the fact that there is no spaces in the strings so it converts it to a "variable" table title instead? That's very annoying…
I have a clue of what it might be. Is it the fact there is no spaces inbetween words in those strings, so it ignores them as strings and converts to a "variable"?
Edited on 24 July 2017 - 12:13 AM