Posted 09 August 2016 - 08:54 PM
I have been having an issue with what I am pretty sure is when I unserialize a table from another file. I am positive the table is serialized correctly and read correctly, but whenever I try to unserialize anything from a file all I get is the 'attempt to concatenate string and nil'. I can get unserialize to work when not reading another file, but that isn't doing me any luck here. Can someone please help me? Thanks ahead. This is the code I get the error from.
Here is the table
Spoiler
local tArgs = {...}
if tArgs[1] == "sethome" then
local hx,hy,hz = gps.locate()
local coords = {x = hx, y = hy, z = hz}
if fs.exists("home") then
fs.delete("home")
end
local file = fs.open("home","w")
file.write(textutils.serialize(coords))
file.close()
print("Home set at "..hx..", "..hy..", "..hz)
end
if tArgs[1] == "home" then
if fs.exists("home") then
local file = fs.open("home","r")
local data = file.readAll()
file.close()
local hx = textutils.unserialize(data.x)
local hy = textutils.unserialize(data.y)
local hz = textutils.unserialize(data.z)
print("Home is at "..hx..", "..hy..", "..hz)
else
print("Home is not set yet.")
print("To set a home type 'goto sethome'")
end
end
Spoiler
{
z = -798,
y = 237,
x = -397,
}