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

Sending a table via rednet doesn't work

Started by Tim3Game, 25 September 2015 - 05:24 PM
Tim3Game #1
Posted 25 September 2015 - 07:24 PM
Hello, i create a little program for my friend for his house to monitorize his energy and input lava and other thing. I make 2 programs (sender to main computer, main computer) and all is going fine, and when i sending a table via rednet and the computer receive it, but the computer that its receiving it, is thinking that isn't a table. Hears pictures from ingame:
http://tim3game.eu/upload/program1.PNG
http://tim3game.eu/upload/program2.PNG

Code:
sender computer:
local info = {
['EnergyStored'] = format_thousand(energy),
['EnergyCapacity'] = format_thousand(maxene),
['FluidName'] = fluidName,
['FluidAmount'] = fluidAmount,
['FluidCapacity'] = fluidCapacity
}
local msg = textutils.serialize(info)

rednet.send(15, info)
main computer:
senderId, message = rednet.receive()
data = textutils.unserialize("message")
and
mon.write(data.EnergyStored.." RF")
Edited on 25 September 2015 - 06:47 PM
gollark8 #2
Posted 25 September 2015 - 08:42 PM
You're un serialising the string "info". You need to unserialise the variable message.

I think Rednet can send tables directly, though.
Tim3Game #3
Posted 25 September 2015 - 08:47 PM
Oh, you right, but i forgot to change it because I was testing something else, but it was "message"
Dog #4
Posted 25 September 2015 - 10:28 PM
With the correction you made, you're now trying to unserialize the string "message", not the variable message - remove the quotes.
Quessith #5
Posted 25 September 2015 - 11:54 PM
shouldnt this part:

local info = {
['EnergyStored'] = format_thousand(energy),
['EnergyCapacity'] = format_thousand(maxene),
['FluidName'] = fluidName,
['FluidAmount'] = fluidAmount,
['FluidCapacity'] = fluidCapacity
}
local msg = textutils.serialize(info)
rednet.send(15, info)

be this?:

local info = {
['EnergyStored'] = format_thousand(energy),
['EnergyCapacity'] = format_thousand(maxene),
['FluidName'] = fluidName,
['FluidAmount'] = fluidAmount,
['FluidCapacity'] = fluidCapacity
}
local msg = textutils.serialize(info)
rednet.send(15, msg)

because now you are just sending over your table (with the rednet.send(15, info) and not the serialized msg
Edited on 25 September 2015 - 09:55 PM
Dog #6
Posted 26 September 2015 - 12:03 AM
Good catch, Quessith - that's yet another problem.

Tim3Game, in addition to the the fix I suggested above, you'll want to change your rednet.send(15, info) to rednet.send(15, msg).

Depending on which version of CC you're using you can send the table without serializing/unserializing - but I'm not sure when that was added - 1.6 maybe? So, if you're using a recent version of CC you can simply use rednet.send(15, info) and skip serializing it into msg - just don't unserialize it into data on the receiving end - then get your info by using message.EnergyStored instead of data.EnergyStored.
Edited on 25 September 2015 - 10:06 PM
Bomb Bloke #7
Posted 26 September 2015 - 01:24 AM
Depending on which version of CC you're using you can send the table without serializing/unserializing - but I'm not sure when that was added - 1.6 maybe?

Somewhere back in the early 1.5x range. Tim3Game's build can do it - otherwise the Lua prompt on the receiving computer wouldn't show the table contents.
Tim3Game #8
Posted 26 September 2015 - 09:24 AM
Thanks you all for helping, its working, i edit the rednet.msg(15, info) to rednet.msg(15, msg) (Thanks Quessith) and removed the serialize and unserialize things (Thanks Dog) and now its doing what i wanted! http://tim3game.eu/upload/program3.png