9 posts
Posted 05 December 2012 - 05:07 PM
Hi guys, so I've just set up a GPS host, and I've tested it and it works great. Now, for the past 2 hours, I have been trying to make a program that sends the computer it's on location over rednet to my computer. Now, since gps.locate() returns a x,y, and z value, I then used tostring() to set them as strings. But to my dismay, when I tried it, it returned nil for all three values when i sent it over rednet with rednet.send. Now after spending 2 hours searching the web and trying everything i can, its now 11:00 and my eyes hurt. Please help me.
Thanks,
-Sodapop98
8543 posts
Posted 05 December 2012 - 05:21 PM
Let's see the code.
145 posts
Location
the vast cosmos of my mind; binary!
Posted 05 December 2012 - 06:44 PM
you could store the information comeing over rednet like this :)/>
--defining local table <coords>
local coords = {x, y, z}
--gps location is being stored in the table <coords>
rednet.recieve(coords)
--getting the variable <coordinate> by itself
coords[x] = <call on the variable> integer
coords[y] = <call on the variable> integer
coords[z] = <call on the variable> integer
--providing the computer/turtle with its location
local location = {
coords[x] = horizontalposition
coords[y] = verticleposition
coords[z] = heightposition
}
now this is just an example but you can use it any other way :)/> your welcome
hit the up button on the lower right for me will' ya
THANKS :)/>
8543 posts
Posted 05 December 2012 - 07:39 PM
That is not how tables work, nor how rednet.receive() works.
9 posts
Posted 06 December 2012 - 02:06 AM
I can't really get the code exactly, because I'm on my iPhone, but this is one of the ways I tried:
local x, y, z = gps.locate(3)
local locX = tostring(x)
local locY = tostring(y)
local locZ = tostring(y)
local location = locX, locY, locZ
rednet.open("top")
rednet.send(39, location)
Like I said, this is only one of the things I tried.
386 posts
Location
France
Posted 06 December 2012 - 02:50 AM
Your location variable should be a table and you use serialize to send it over rednet and unserialize to receive it :)/> itns the textutils API on the wiki :P/>
1688 posts
Location
'MURICA
Posted 06 December 2012 - 03:19 AM
That's almost right. Just change this line to:
local location = locX..' '..locY..' '..locZ
You can also remove the tostring()s above it, since using .. automatically converts numbers to strings.
On the receiving computer, you can use string.match to get your positions.
local id, msg = rednet.receive()
local locX, locY, locZ = msg:match('(%d+) (%d+) (%d+)')
9 posts
Posted 06 December 2012 - 03:59 AM
Just tried above code, i am getting a error saying
"Attempted to concatenate string and nil"
8543 posts
Posted 06 December 2012 - 06:32 AM
If you did remove the tostring()s above it, you should then change it to use x, y, and z. You should also check to make sure that you're getting good results back from gps.locate.
9 posts
Posted 06 December 2012 - 06:41 AM
Just tried both of them. GPS works and even with x, y, and z it gives me the same error
8543 posts
Posted 06 December 2012 - 06:43 AM
Well, let's see the current code.
2005 posts
Posted 06 December 2012 - 07:35 AM
Before sending your rednet message, put a debug print like: print(type(x),":",x,",",type(y),":",y,",",type(z),":",z)
That way you know for sure what's in x,y, and z.
9 posts
Posted 06 December 2012 - 08:37 AM
Ok, I finally got it to work. Thanks guys.