Spoiler
a = {
name = "stone",
pos1 = 1,
pos2 = 1,
[etc...]
}
b = {
name = "dirt",
pos1 = 1,
pos2 = 2,
[etc...]
}
c = ...
d = ...
etc...
table = {a, b, c, [etc...]}
now, I want to save this table in a file:
Spoiler
function save(table, filename)
hWrite = fs.open(filename, "w")
for i = 1, len(table), 1 do --len() is a function I created to determine the length of a table
hWrite.write(textutils.serialize(table[i]))
hWrite.write("\n")
end
hWrite.write("--End--")
hWrite.close()
end
So far so good, this works very well… So heres the problem:
my load function looks like this:
Spoiler
function load(filename)
hRead = fs.open(filename, "r")
local i = 1
local ret = {]
while true do
local x = hRead.readLine(i)
if x == "--End--" then break end
ret[i] = textutils.unserialize(x)
i = i+1
hRead.close()
return ret
end
Now what I realized:
The serialize thing writes the table in paragraphs, and the reaLine() only reads one line…
So instead of '{name = "stone", pos1 = 1, pos2 = 2, [etc…]}' it just reads '{'.
Any good approach for fixing this?