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

Half Problem, Half Suggestion.

Started by IndustrialLemon, 04 July 2014 - 12:04 AM
IndustrialLemon #1
Posted 04 July 2014 - 02:04 AM
So here's the dealio. I've been working on a program to send a turtle your coords from a pocket computer.

The problem? Well, I have the pocket computer printing my coords and it looks fine, but when I send them over rednet to the turtle, they get some funky numbers.

So the half and half situation is…Can you fix my program so I can move on? Or can you make it!

Heres the turtle code.(Receiving)
print(rednet.receive())
print(rednet.receive())
print(rednet.receive())

And here's the pocket computer code.(Sender)
rednet.open("back")
x, y, z, w, q, v = gps.locate()
print(x)
print(y)
print(z)
print(w)
rednet.broadcast(x)
rednet.broadcast(y)
rednet.broadcast(z)
rednet.broadcast(w)

Thank you! And I really hope I don't have to over-complicate this.
Dog #2
Posted 04 July 2014 - 02:49 AM
rednet.receive() returns two pieces of information (sender id & message). Try this…

local id, message = rednet.receive()
print(message)

instead of this…

print(rednet.receive())

Hope that helps :)/>


p.s. Lemons are pretty good
Edited on 04 July 2014 - 12:51 AM
IndustrialLemon #3
Posted 04 July 2014 - 03:19 AM
Hey btw! I wanted to talk to you actually! I was curious if you would want a video done on your gtRemote. Oh and now there's a problem with my sender. It wont even print or send coords. So I have no idea if its working or not. Code for it hasn't changed :/
Dog #4
Posted 04 July 2014 - 04:47 AM
First, your program…

gps.locate() only passes 3 values (x,y,z coords), so you might want to try…

local x,y,z = gps.locate()
print(x)
print(y)
print(z)
rednet.broadcast(x)
rednet.broadcast(y)
rednet.broadcast(z)

It seems to me that you should still be getting x,y & z the way you are doing it (with the remainder being nil), but try that and see if that fixes it. If that doesn't fix it, double check your GPS hosts (if one or more crashed or failed to boot up that might explain it).

Regarding a video for gtRemote - that'd be great! Thank you for the offer. Send me a PM and we'll work out any details :)/>
IndustrialLemon #5
Posted 04 July 2014 - 05:24 AM
I think the problem was I was too far away from the gps. Now the only problem is that it only gives me an x coord.
Edited on 04 July 2014 - 03:29 AM
Dog #6
Posted 04 July 2014 - 06:06 AM
strange…I just ran the following code without problems…

local x,y,z = gps.locate()
print(x)
print(y)
print(z)

Would you post the code you have as it is so I can look it over?
IndustrialLemon #7
Posted 05 July 2014 - 05:19 PM
Turtle Code
local id, x, y, z = rednet.receive()
print(x)
print(y)
print(z)

Pocket Code
rednet.open("back")
local x, y, z = gps.locate(3)
rednet.broadcast(x)
rednet.broadcast(y)
rednet.broadcast(z)

I've also replaced the gps tower completely with new computers and now I'm going to try to use an OS.pullEvent function.
Lyqyd #8
Posted 05 July 2014 - 05:28 PM
Three rednet broadcasts would need to be received by three rednet.receive calls, not one.
IndustrialLemon #9
Posted 05 July 2014 - 05:33 PM
Alright. It works now with the os.pullEvent()! However! The whole purpose of this program was to be constantly telling your turtle your coords so it can follow you around, and now that I've added a while true do and a shell.run("goto"..x, y, z) it says "no such program" when it gets a message. What should I do about this?

@Lyqyd Yeah I realized that and even adding a while true do didn't help entirely until I made it an event.
.
Edited on 05 July 2014 - 03:34 PM
Dog #10
Posted 06 July 2014 - 12:35 AM
shell.run("goto" .. x,y,z) ?

Do you have a "goto" program? To my knowledge turtles don't have such an ability unless your write a program to do that.
IndustrialLemon #11
Posted 06 July 2014 - 12:47 AM
Yes I do.
Dog #12
Posted 06 July 2014 - 12:53 AM
OK, then. Make sure 'goto' and your other program are in the root directory (for simplicity) and that 'goto' is actually 'goto' (all lower case) and not a mix of C/LC.

Next (and this might be the problem…I don't have a way to test, atm) try different syntax…

shell.run("goto x y z")

and see what happens. My shell-fu is not strong, so the suggested syntax may be incorrect…
Edited on 05 July 2014 - 10:54 PM
Bomb Bloke #13
Posted 06 July 2014 - 02:12 AM
It's incorrect. You'd be passing x/y/z the characters, as opposed to x/y/z the variables.

Turtles have a built-in "go" script, though it doesn't support co-ords to my knowledge. Just basic stuff like "forward", "back", etc.

Assuming there's a "goto" script on this particular turtle which does support co-ords, you'd do this:

shell.run("goto",x,y,z)

Or this:

shell.run("goto "..x.." "..y.." "..z)

Though frankly I'd rather see it packed up into an API.
Dog #14
Posted 06 July 2014 - 02:17 AM
Thanks for correcting me, Bomb Bloke :)/> It's an obvious error now that I look at it…d'oh!