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

[Lua][Problem][Question]Rednet Communication Server

Started by Kryptanyte, 13 November 2012 - 09:44 PM
Kryptanyte #1
Posted 13 November 2012 - 10:44 PM
I've been trying create a sort of central rednet server for my house so it can handle sending information between different clients and excecute its own functions if called on. There are backup servers designed so that if the main is not able to send any information to the sending client it will automatically send to another of the server. However seeing as though some of the sending is based on inputs from a user, like [Recipient ID], [Message]. (For example; 4, Hello! ) Im not sure how to send this all in one line. As it is all one line from the input.

Is this even possible?

I may be asking the impossible here, if its not possible I can just go back to a simple send with a line break between then have the server split the message itself.


cheers
MetalMiner #2
Posted 14 November 2012 - 12:42 AM
I suggest you to send serialized tables:

Client

local table = {4, "hello!"}
local sTable = textutils.serialize(table)
rednet.send(serverID, sTable)
Server

local id, msg = rednet.receive()
local table = textutils.unserialize(msg)
print(table[2])            --will print "hello!"

Hope I helped!
Heracles421 #3
Posted 14 November 2012 - 01:39 AM
Yea, it's possible to do that but you'll have to create multiple variables and later on asign them to rednet.send() function.
Kryptanyte #4
Posted 14 November 2012 - 07:42 AM
Odd I tried this last night but was getting rednet:350 errors when I tried to send it. But this doesn't answer the entire question. I still need to know if its possible to split a single line up after the comma.
Lyqyd #5
Posted 14 November 2012 - 08:47 AM
Use string.match. This may do what you're looking for:

beforeComma, afterComma = string.match(inputString, "(.-),(.*)")
Kryptanyte #6
Posted 14 November 2012 - 10:51 PM
Thanks Lyqyd, thats exactly what I needed.