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

[Lua][Error]

Started by IceCrasher, 30 September 2012 - 06:35 PM
IceCrasher #1
Posted 30 September 2012 - 08:35 PM
Hi guys, I got the following error message, i can't find out the problem since 2 hours :)/>/> :

startup:4: attempt to cancatenate
string and nil


when i tipe in the shell "gps locate" it works

and here is my programm:


rednet.open("right")
x, y, z = gps.locate

print (x..", "..y..", "..z)

How can I save the gps coordinates in x, y and z and show me them by printing on the screen?

Thank you for helping

IceCrasher
Lyqyd #2
Posted 30 September 2012 - 08:36 PM
You'll need the parentheses:


x, y, z = gps.locate()
MysticT #3
Posted 30 September 2012 - 08:38 PM
You need to call the gps.locate function, like this:

local x, y, z = gps.locate(1) -- it needs a timeout in seconds, you can change it to whatever you want
if x and y and z then -- check if it could get the position (when it times out the position is nil)
  print(x, ", ", y, ", ", z)
else
  print("Couldn't get position")
end
IceCrasher #4
Posted 30 September 2012 - 08:39 PM
okay, I did it an now i get the following error message:

gps:69: attempt to compare nil with
number
MysticT #5
Posted 30 September 2012 - 08:40 PM
You need to add the timeout parameter like I did.
IceCrasher #6
Posted 30 September 2012 - 08:43 PM
thank you so much xD It's working now *_*
Lyqyd #7
Posted 30 September 2012 - 08:45 PM
You need to add the timeout parameter like I did.

Oh, interesting. I guess I thought it worked like the rednet calls' timeout parameter. I suppose not.
MysticT #8
Posted 30 September 2012 - 08:47 PM
See this thread for more info.