This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
gollark8's profile picture

Airship flight logging system : flightlog:1:string,string expected.

Started by gollark8, 14 December 2013 - 09:48 AM
gollark8 #1
Posted 14 December 2013 - 10:48 AM
I am trying to log my airship parking locations.

I have a gps system set up.When I try to run it,I get the error in the title.There is also a disk drive with a disk in it beside the computer.


local flightlog = fs.open("disk/flightlog")
while true do
local pos = gps.locate()
print(pos)
file.write(pos)
sleep(10)
end
Edited on 14 December 2013 - 09:48 AM
MKlegoman357 #2
Posted 14 December 2013 - 11:17 AM
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
CoderPuppy #3
Posted 14 December 2013 - 11:17 AM
You need to tell it what mode to open the file in:

fs.open("disk/flightlog", "w")
w for write
r for read
Bomb Bloke #4
Posted 14 December 2013 - 11:18 AM
fs.open() requires two parameters: A string, and another string.

Eg, fs.open("disk/flightlog","w")

Edit: lolninja
Edited on 14 December 2013 - 10:18 AM
Ajt86 #5
Posted 16 December 2013 - 07:08 AM
If you want to locate a computer or turtle like a real GPS you could use three servers, and put all three distances in a GPS algorithm. Or you could log every single movement of the turtle (which wouldn't be real GPS)