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

Textutils:166: Cannot Serialize Type Function

Started by campicus, 31 July 2013 - 06:29 AM
campicus #1
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
LBPHacker #2
Posted 31 July 2013 - 08:35 AM
t[6] = tStatus
is the problem. Should be
t[6] = status
(tStatus is a function)
campicus #3
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!
jesusthekiller #4
Posted 31 July 2013 - 09:01 AM
-snip, nvm-
campicus #5
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
LBPHacker #6
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?
campicus #7
Posted 31 July 2013 - 09:17 AM
Yes sorry
LBPHacker #8
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".
campicus #9
Posted 31 July 2013 - 09:26 AM
Thanks again! I will get there eventually I swear (haha)
GamerNebulae #10
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
campicus #11
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