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

rednet broadcasting gps location doesn't work with v1.5

Started by Scoldpedia, 23 May 2014 - 08:09 PM
Scoldpedia #1
Posted 23 May 2014 - 10:09 PM
Just learned the basics of LUA and decided to try my new knowledge out in ComputerCraft.
Up until this point I've mostly just used pastebins, but started adding my own code.

So I've set up a gps gobal positioning system using this guide. Everything works fine, I've no trouble getting my location with gps locate or

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

Of course I wanted to take it a step further and see if I could use rednet.broadcast to send my turtles location to a receiving computer. Tested rednet.broadcast, works fine. made this simple little code:

local x, y, z =gps.locate()
if x== nill then
  print("fail whale")
else
  rednet.broadcast(" ",x," ",y," ",z)
end

But all I get is an empty message. I've tried simplifying it, so it just defines the gps variable and then sends it, but it makes no difference. It just simply won't broadcast the turtle location to my receiving computer.
The server I'm using is only on OS 1.5, but I can't imagine that would be the problem. can anyone please help me!
Lyqyd #2
Posted 23 May 2014 - 10:24 PM
Rednet.broadcast will send its first argument out. The first argument you are providing is " ", a single space character. You've gotten confused because print accepts as many arguments as you'd like to give it and simply tostring()s and concatenates them as it writes them on to the screen. You will need to use genuine concatenation to combine those arguments into a single string. Try doing this instead:


rednet.broadcast(x.." "..y.." "..z)

The two periods you see between the various elements above is the concatenation operator.
Scoldpedia #3
Posted 23 May 2014 - 10:30 PM
Then the wiki should probably be updated accordingly, because I got the code from here

But thank you so much! I've been pulling my hair out for 2 hours now :mellow:/>
Bubba #4
Posted 23 May 2014 - 10:32 PM
Then the wiki should probably be updated accordingly, because I got the code from here

But thank you so much! I've been pulling my hair out for 2 hours now :mellow:/>

On the wiki the code is using print, not rednet.broadcast. They function differently. Print allows you to pass as many arguments as you want. rednet.broadcast does not.

However, I do understand how the code might be confusing for beginners. I'll go ahead and edit it to be a bit nicer.
Edited on 23 May 2014 - 08:41 PM
Lyqyd #5
Posted 23 May 2014 - 10:34 PM
The code on that page is fine because print handles multiple arguments just fine, printing all of them to the screen, whereas rednet.broadcast only uses its first argument. The problem in your code was that you were trying to use rednet.broadcast as if it were print. The wiki page there only appears to be using print that way, so I'm confused as to what would need updating.