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

Rednet Question

Started by mougli123, 02 July 2012 - 09:12 PM
mougli123 #1
Posted 02 July 2012 - 11:12 PM
I'm just wondering if it would be possible to send more than 1 piece of information through rednet. Like instead of a message like

id,msg = rednet.receive()
it would be

id, msg, ext = rednet.receive()
where ext would contain an extra piece of information. I'm asking this because I'm making an ore handler and I need to send from one computer to another an amount and a type at the same time and check if the received value is lower than the stored value and every time I try the computer receiving says "attempt to compare string with number expected, got string"
MysticT #2
Posted 02 July 2012 - 11:37 PM
You can use a table and serialization:
Sender:

local ore = {}
ore.type = "Iron"
ore.amount = 64
rednet.send(id, textutils.serialize(ore))

Receiver:

local id, msg = rednet.receive()
local ore = textutils.unserialize(msg)
print(ore.type, ": ", ore.amount)

And you can send lots of information inside the table.
mougli123 #3
Posted 02 July 2012 - 11:59 PM
Thank you very much. That was exactly what I needed to make it work