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

Broadcast and Recieve Rednet messages

Started by The_Puzzlemaker, 04 December 2016 - 01:38 AM
The_Puzzlemaker #1
Posted 04 December 2016 - 02:38 AM
I have a script that I have, and I want it inside an infinite loop to broadcast a message, and print any received messages.

Is this possible?
Edited on 04 December 2016 - 01:39 AM
KingofGamesYami #2
Posted 04 December 2016 - 02:45 AM
It is absolutely possible.

local id = os.startTimer(0)
while true do
  local event = {os.pullEvent()}
  if event[ 1 ] == "timer" and event[ 2 ] == id then
    id = os.startTimer(1) --#sending one message a second should be sufficient.
    rednet.broadcast( "a message" )
  elseif event[ 1 ] == "rednet_message" then
    print( event[ 3 ] )
   end
end
Edited on 04 December 2016 - 01:46 AM
The_Puzzlemaker #3
Posted 04 December 2016 - 02:48 AM
It is absolutely possible.

local id = os.startTimer(0)
while true do
  local event = {os.pullEvent()}
  if event[ 1 ] == "timer" and event[ 2 ] == id then
	id = os.startTimer(1) --#sending one message a second should be sufficient.
	rednet.broadcast( "a message" )
  elseif event[ 1 ] == "rednet_message" then
	print( event[ 3 ] )
   end
end
Thanks!