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

Get multiple Variables over a singe rednet message

Started by bastrian, 21 September 2012 - 09:13 PM
bastrian #1
Posted 21 September 2012 - 11:13 PM
Hi,
I tryed to figure out how i could get 2 variables over a single rednet message.
I read already this topic:http://www.computerc...h__1#entry28710
but i could not understand it really.
My idea was that a rednet message get splitted into 2 Variables. Here a example what i mean:
http://pastebin.com/DnRRGSAh

Thx,
bastrian
MetalMiner #2
Posted 21 September 2012 - 11:23 PM
Hi
You can use a table:

value1 = 5
value2 = "example"
table = {value1, value2}		   --creates a table with two variables
msg = textutils.serialize(table)	--Converts the table ta a string
rednet.send(id, msg)

id, msg = rednet.receive()
table = textutils.unserialize(msg)  --Converts the string back to a table
value1 = table[1]
value2 = table[2]

hope this helped!