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

How to send multiples variables in one rednet message

Started by Matt21, 08 December 2012 - 09:39 PM
Matt21 #1
Posted 08 December 2012 - 10:39 PM
This is a little tutorial to send multiples messages in one message with rednet.
First, use string.gmatch at the receiver to separate the messages like this:


senderId, message, distance = rednet.receive() -- Wait for a message
multiMessages = { } -- Declare a table. It will contains the messages
for w in string.gmatch(message, "%s+") do -- Separate the messages
multiMessages[#multiMessages + 1] = w -- Add all messages in the table
end

You will fond more information about the "%s+" (line 3) here.

Next, use normal rednet sender at the sender:


print "First message to send?"
message1 = read() -- Input
print "Second message to send?"
message2 = read() -- Input
print "Id of the computer?"
sId = read() -- Input
id = tonumber(sId) -- Convert string to a number
rednet.send(id, message1 .. " " .. message2) -- Send messages

Have fun!

(sorry for my bad english)
PixelToast #2
Posted 09 December 2012 - 03:46 AM
you can also serialize a table
its alot easier than messing around with patterns and wont break when you have a space
Learning_inpaired #3
Posted 20 December 2012 - 03:12 PM
what if i need to send multi-lines of data to multi "clients" from a master "server"?
i know theres a rednet.broadcast() thing but how can i mix the 2?

I dont have the code put together yeat, lacking skill. just makeing many notes atm
PixelToast #4
Posted 20 December 2012 - 03:35 PM
why not just send it to individual clients?
its more efficient than broadcast