Crucidal, on 13 August 2014 - 08:06 PM, said:
Actually, I didn't use that function yet.
It sounds like you've already seen your mistake in saying that, but movementAPI.move() calls getLocation() followed by setLocation() again.
Sometimes, when a function fails within an API, it can be handy to intersperse random print statements throughout your main scripts so you can tell exactly how far the script got before making the final call that crashed. Some other languages - eg Java - make this a lot easier by handing you the entire list of functions sitting in the stack along with the lines they were called from and of course your error message as well.
hilburn, on 13 August 2014 - 08:33 PM, said:
Psst, you mean
unserialise!
Anyway, to elaborate on this, it'd work along these lines: First you'd initialise a table with your values in it:
local myVars = {["x"] = 0, ["y"] = 0, ["z"] = 0, ["d"] = 0}
You'd now be able to refer to these variables as myVars.x, myVars.y, and so on.
textutils.serialise() can then be used to convert the entire table and its contents to a single string (a series of characters - get it?), which you can write to disk like so:
--setLocation and direction
local function setLocation()
local locationFile = fs.open("location", "w")
locationFile.write(textutils.serialise(myVars))
locationFile.close()
end
And then to read it,
textutils.unserialise() comes into play:
--getLocation
function getLocation()
local locationFile = fs.open("location", "r")
myVars = textutils.unserialise(locationFile.readAll())
locationFile.close()
end
Crucidal, on 13 August 2014 - 09:34 PM, said:
gx, gy, gz = locationFile.readAll():match("([^,]+),([^,]+), ([^,]+)")
this code doesn't seem to work but I don't know how else to do this... any ideas?
Something like this:
gx, gy, gz = locationFile.readAll():match("(.*%d*),(.*%d*),(.*%d*)")
The stuff outside the brackets has to be matched verbatim - that includes spaces, so be careful! Within the brackets, ".*" means "get everything until the next match", and "%d*" means "get all digits until the next match".
It may be that you can't apply "match" directly to "locationFile.readAll()". You may need to read the file contents into a variable, then apply "match" to that variable on the following line.