There are a few problems with your code:
1.
fs.open takes 2 arguments: path to the file and in which mode to open that file (read, write, read bytes, etc.):
2. There is no
file variable in your code. I think you meant
flightlog.
3.
gps.locate returns 3 variables: x, y and z coordinates of the computer.
Fixed code would look like this:
local flightlog = fs.open("disk/flightlog", "a") --// Open the file in append mode, so we could add text to the file.
while true do
local x, y, z = gps.locate()
local pos = x .. ", " .. y .. ", " .. z
print(pos)
flightlog.writeLine(pos) --// Write a line in the file
sleep(10)
end
You also never close the file. You can close it by using the
close method in the file handle:
flightlog.close()
--// When you close the file it is properly saved to the computer.
--// After you close it you can no longer use the file handle to read/write a file