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

[Error] gps locate works, but gps.locate does not

Started by Herr_Rechner, 27 December 2012 - 12:18 PM
Herr_Rechner #1
Posted 27 December 2012 - 01:18 PM
I'm trying to make a program and part of it requires a turtle to return to its starting position. In order to do this, I have ecided to get the starting coordinates with the gps api. Whenever I run gps locate in the shell, it returns the x, y, and z almost instantly. However, when I run gps.locate inside a program it always says that it can not determine the coordinates. Is there a way to fix this, or could I obtain the coordinates alternatively by running shell.run("gps, locate")?
BustedEarLobes #2
Posted 27 December 2012 - 01:19 PM
I'm trying to make a program and part of it requires a turtle to return to its starting position. In order to do this, I have ecided to get the starting coordinates with the gps api. Whenever I run gps locate in the shell, it returns the x, y, and z almost instantly. However, when I run gps.locate inside a program it always says that it can not determine the coordinates. Is there a way to fix this, or could I obtain the coordinates alternatively by running shell.run("gps, locate")?
Can you post the code please?
Herr_Rechner #3
Posted 27 December 2012 - 02:00 PM
This is the code from the wiki that I've been experimenting with. I can run gps locate fine, but if I run a program with this code, it can't determine the coordinates. I have tried changing the timeout to a longer period, but even then it doesn't work so I figure that isn't the issue. I don't know how to indent on this post, but it is indented on the 4th and 6th lines.

print("Man I am so lost right now!")
local x, y, z = gps.locate(5)
if x == nil then
print("Nope, still lost :(/>")
else
print("I am at ",x," ",y," ",z)
end
Doyle3694 #4
Posted 27 December 2012 - 02:01 PM
well having such a short timeout is probably not so good…
Lyqyd #5
Posted 27 December 2012 - 02:04 PM
That function doesn't work at all without a timeout specified.
Doyle3694 #6
Posted 27 December 2012 - 02:06 PM
oh, but atleast lenghten them timeout.
Herr_Rechner #7
Posted 27 December 2012 - 02:48 PM
But the timeout is specified, that is what the 5 in "gps.locate(5)" is, isn't it? On the wiki it states " gps.locate(timeout, debug) " as the correct format. Even when I increase the timeout to a minute and set debug to true, it still doesn't return the coordinates. This confuses me because running gps locate instead of a program with gps.locate will instantly return the coordinates.

Link to the wiki I've been using: http://computercraft.info/wiki/index.php?title=Gps_%28API%29
Lyqyd #8
Posted 27 December 2012 - 02:51 PM
I was disagreeing with Doyle's pre-edit post. Try using gps.locate in debug mode, see what it says.
Herr_Rechner #9
Posted 27 December 2012 - 03:13 PM
Ok in gps.locate in debug mode says:

Man I am so lost right now!
Finding Position…
Could not determine position
Nope, still lost :(/>


Then just running gps locate in the shell says:

No modem active. Opening right modem
Finding position…
188 meters from 0, 3, 255
188 meters from 0, -3, 255
185 meters from 3, 0, 252
185 meters from -3, 0, 252
Position is 1, 1, 67
ChunLing #10
Posted 27 December 2012 - 03:18 PM
You didn't open the modem, did you? The gps program automatically opens the modem, and then closes it again once done.
Herr_Rechner #11
Posted 27 December 2012 - 03:25 PM
Yeah, I didn't open the modem. It's working now that I did, so thanks!
ChunLing #12
Posted 27 December 2012 - 04:24 PM
Opening modems…it's like the bane of your CC existence at a certain stage. There are in fact several good reasons that modems are not always on, but man, it's an inexplicably difficult hurdle to get used to doing something so simple.

I can't wait till we have rednet PDA's (or whatever they decide to call them), and this forum is full of nothing but "my PDA doesn't work" posts.