Jump to content




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


  • You cannot reply to this topic
4 replies to this topic

#1 gollark8

  • Members
  • 207 posts

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 by gollark8, 14 December 2013 - 10:48 AM.


#2 MKlegoman357

  • Members
  • 1,170 posts
  • LocationKaunas, Lithuania

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


#3 CoderPuppy

  • Members
  • 121 posts

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

#4 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

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 by Bomb Bloke, 14 December 2013 - 11:18 AM.


#5 Ajt86

  • Members
  • 42 posts

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)





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users