162 posts
Posted 31 July 2013 - 08:29 AM
I am trying to make my turtle send its coordinates via rednet but I get the above error. Any ideas?
Spoiler
local xPos = 1
local yPos = 1
local zPos = 1
local nMoved = 1
local nReturned = 1
local error = 1
local status = 0
function tStatus()
xPos, yPos, zPos = gps.locate(5)
t = {}
t[1] = xPos
t[2] = yPos
t[3] = zPos
t[4] = nMoved
t[5] = nReturned
t[6] = tStatus
print("Position is "..xPos..","..yPos..","..zPos )
sleep(1)
rednet.open("right")
local message = textutils.serialize(t)
rednet.broadcast(msg)
end
function move()
status = 1
repeat
sleep(0.1)
error = error+1
if error == 10 then
status = 0
end
until turtle.forward()
nMoved = nMoved+1
tStatus()
end
while true do
for x = 1,5 do
move()
end
turtle.turnLeft()
turtle.turnLeft()
for x = 1,5 do
move()
end
end
758 posts
Location
Budapest, Hungary
Posted 31 July 2013 - 08:35 AM
t[6] = tStatus
is the problem. Should be
t[6] = status
(tStatus is a function)
162 posts
Posted 31 July 2013 - 08:38 AM
Ah man, I had tStatus as both a var and function, which I thought I had fixed all instances but apparently not. You're actually a legend, thanks mate!
587 posts
Location
Wrocław, Poland
Posted 31 July 2013 - 09:01 AM
-snip, nvm-
162 posts
Posted 31 July 2013 - 09:11 AM
Ok, more issues, now on the receiving side. I'm not really sure what I am doing, don't hate the noob!
I have:
rednet.open("right")
while true do
local id, message = rednet.receive()
local t = textutils.unserialize(message)
print("Pos: "..t[1]..","..t[2]..","..t[3])
end
758 posts
Location
Budapest, Hungary
Posted 31 July 2013 - 09:13 AM
rednet.open("right")
while true do
local id, message = rednet.receive()
local t = textutils.unserialize(message)
print("Pos: "..t[1]..","..t[2]..","..t[3])
end
And what's the error? concat string and nil?
162 posts
Posted 31 July 2013 - 09:17 AM
Yes sorry
758 posts
Location
Budapest, Hungary
Posted 31 July 2013 - 09:22 AM
Version of ComputerCraft?
EDIT: Nevermind, the problem is in the sender: you serialize the table and put it into "message", then you send "msg", not "message".
162 posts
Posted 31 July 2013 - 09:26 AM
Thanks again! I will get there eventually I swear (haha)
215 posts
Location
Netherlands
Posted 01 August 2013 - 05:43 AM
Thanks again! I will get there eventually I swear (haha)
I said that once with an API I tried making, but I gave up, because it got so cluttered and had over 800 lines xD
162 posts
Posted 01 August 2013 - 05:46 AM
Every mistake I make is one that I am less likely to repeat :P/> That's what I keep telling myself… lol