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

rednet.send non text messages

Started by Joroba3, 11 December 2015 - 08:09 PM
Joroba3 #1
Posted 11 December 2015 - 09:09 PM
hello, I'm triying to make like a server were other computers can connect so the main computer is broadcasting constantly until it receives a message from a computer that want's to connect. I made a table with some parameters for this broadcast. One of them is the message I want to broadcast (in this case mainserver ). So I made this code.(This is not the full code but is the thing that keeps failling.

--Tables
local broadcast = {message = name, frequency = 0.1}
--Variables
local name = "MainServer"
--Functions
function broadcast ()
rednet.broadcast(broadcast["message"],MainServer)
sleep(broadcast["frequency"])
end

Is there any way I could send it from a table?

thanks
Bomb Bloke #2
Posted 12 December 2015 - 12:38 AM
You initialised the variable "name" to hold the string "MainServer", but you never initialised a "MainServer" variable to use in this line:

rednet.broadcast(broadcast["message"],MainServer)  -- Switch MainServer to either name or "MainServer"

If you want to send a table via rednet, simply send the table. Unless you're on a rather old version of ComputerCraft (in which case you'd need to make use of textutils.serialise()), most data types can be sent directly, not just strings.

Really though this isn't the best way to go about it. The server should be listening for broadcasts from clients, not the other way around, as that way broadcasts only occur when clients want to connect.

As of CC 1.6, there's actually a few built-in functions for this specific purpose - see rednet.lookup().
Joroba3 #3
Posted 12 December 2015 - 09:49 AM
thanks for answering.
First, the
You initialised the variable "name" to hold the string "MainServer", but you never initialised a "MainServer" variable to use in this line:

rednet.broadcast(broadcast["message"],MainServer)  -- Switch MainServer to either name or "MainServer"

If you want to send a table via rednet, simply send the table. Unless you're on a rather old version of ComputerCraft (in which case you'd need to make use of textutils.serialise()), most data types can be sent directly, not just strings.

Really though this isn't the best way to go about it. The server should be listening for broadcasts from clients, not the other way around, as that way broadcasts only occur when clients want to connect.

As of CC 1.6, there's act
ually a few built-in functions for this specific purpose - see rednet.lookup().

Thanks for answering.
First of all, As I said , I didn't post the whole code, that's why the name variable isn't being used.

What I want to send is the message that the table has on it not the table so, would that also be used with serialize?
thanks
Bomb Bloke #4
Posted 12 December 2015 - 10:07 AM
If you wanted to send the "message" key from the "broadcast" table, then your code already appears to do exactly that; the only obvious issue is that you seem to be neglecting to use a protocol.

If your code is erroring, then post the error messages.

If you're simply unable to receive the message, then post the receiving code.

Don't bother saying what "doesn't work" - explain what does happen, and how that differs from what you want.