Posted 13 January 2013 - 06:55 PM
Hello.
There's data that my turtle's hold, and they save it to a file when a program finishes running. One piece of data, for example, are the current coordinates. Also, if I want to log off while they are in the middle of a program, I have a rednet wireless call from my main computer that has them save their position, state, etc. so that they can continue their work when starting up again.
After the startup is where the problem arises. One startup, it loads the information from the file, and such information that gets used a lot, like the position variable X, Y, and Z, get loaded into global variables. Everything runs smoothly, I can use these variables during startup, no problem. Everything works fine, and there is no problem with my code.
After startup, however, whenever I call these global variables, they all are "nil". Is there a particular reason for this?
Here is my code. getCoords() just prints the coordinates to the screen (which works fine if this gets called during startup, but after startup, it fails).
Thanks in advance! :D/>
There's data that my turtle's hold, and they save it to a file when a program finishes running. One piece of data, for example, are the current coordinates. Also, if I want to log off while they are in the middle of a program, I have a rednet wireless call from my main computer that has them save their position, state, etc. so that they can continue their work when starting up again.
After the startup is where the problem arises. One startup, it loads the information from the file, and such information that gets used a lot, like the position variable X, Y, and Z, get loaded into global variables. Everything runs smoothly, I can use these variables during startup, no problem. Everything works fine, and there is no problem with my code.
After startup, however, whenever I call these global variables, they all are "nil". Is there a particular reason for this?
Here is my code. getCoords() just prints the coordinates to the screen (which works fine if this gets called during startup, but after startup, it fails).
function saveCoords()
local h = fs.open("coords", "w")
h.writeLine(tostring(X))
h.writeLine(tostring(Y))
h.writeLine(tostring(Z))
h.close()
print("Save successful!")
end
function loadCoords(source)
local h = fs.open(source, "r")
X = tonumber(h.readLine())
Y = tonumber(h.readLine())
Z = tonumber(h.readLine())
h.close()
print("...")
print("Loading Complete!")
getCoords()
end
Thanks in advance! :D/>