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

Simple RedNet Message Board Monitor

Started by BenAgain, 18 March 2012 - 12:31 PM
BenAgain #1
Posted 18 March 2012 - 01:31 PM
Here's two sister programs I made for an airport in my singleplayer/Hamachi world. One program is for computers to broadcast messages to the monitor, and the other will print the message to the monitor and automatically time stamp it with the in-game time.

Broadcaster

term.clear()
rednet.open("back")
term.setCursorPos(1,1)
print("Airport Board Updater")
message = io.read()
rednet.send(0, message)

Reciever

term.clear()
term.setCursorPos(1,1)
rednet.open("left")
while true do
id, message = rednet.receive()
redstone.setOutput("back", true)
local nTime = os.time()write(textutils.formatTime( nTime, false))
print (" - "..message)
print ()
sleep(1)
redstone.setOutput("back", false)
end

Of course, it must be changed a little to accomidate modem position and computer ID. Also, the reciever program must be run through the monitor, like "Monitor Right BoardGet" or something. The reciever program also has a redstone output bit, which I used to make a little 'ding dong' with two note blocks avec repeaters, and a light to even more so get people's attention.
This is the first program I made, as it was the first idea I got. I hope you peoples find it usefull.
Wolvan #2
Posted 19 March 2012 - 01:00 AM
Nice :D/>/> Good work buddy that programm has potential
MathManiac #3
Posted 18 May 2012 - 01:00 AM
That is awesomesauce. 'Nuff said.
Stevenseegal #4
Posted 11 August 2012 - 07:05 PM
This is a really awesome idea. I love it!
I played the whole day with it and added:
- Monitor support (any size will do but it has to be at least 2 blocks heigh)
- Configurable text size on the monitor
- Configurable redston output (able to choose whenever you want to use the output)
- Text on the monitor will scroll when it's on the end but the header will stay on top
- The client will stay open for input unless you type quit

As i don't see any copyright or ask me befor post i's like to share it with you.

Again thanks for this lovely idea

Server code
Spoiler

local monside = "left" -- Define the side of your monitor
local mdmside = "back" -- Define the side of your modem
local montextsize = 2 -- Define the size of the text on your monitor
local header = "Message Board" -- Type the header of your board
local rson = false -- true is use redstone output, false don't uses the output
local rsoutput = "right" -- Define the redstone output towards a bell of light or something (only needed when rson is set to true)
local rstime = 1 -- The time the redstone output is open
mon = peripheral.wrap(monside)
mon.setCursorBlink(false)
mon.setTextScale(montextsize)
local monwidth, monheight = mon.getSize()
local messages = {}
local num = 0
local messageBegin = 0
local messageEnd = 0
local maxMessagesOS = monheight-3
function monprint(text)
  local cX,cY = mon.getCursorPos()
  mon.write(text)
  mon.setCursorPos(1,cY+1)
end
function clearscreen()
  mon.clear()
  mon.setCursorPos(1,1)
  monprint(header)
  mon.setCursorPos(1,3)
end
function addmessage(text)
  if #messages > maxMessagesOS then
    messageBegin = (#messages - maxMessagesOS)
    messageEnd = #messages
  elseif #messages <= maxMessagesOS then
    messageEnd = #messages
  end
  clearscreen()
  for b = messageBegin, messageEnd do
    monprint(messages[b])
  end
end
function init()
  clearscreen()
  running = true
end
init()
term.clear()
term.setCursorPos(1,1)
print("Message Board SERVER")
print("Press q to quit")
rednet.open(mdmside)
while running do
  event, id, receivedmessage = os.pullEventRaw()
  if event == "rednet_message" then
    local nTime = os.time()
    messages[num] =(textutils.formatTime( nTime, false).." - "..receivedmessage)
    num = num+1
    addmessage()
    if rson then
	  rs.setOutput(rsoutput, true)
	  sleep(rstime)
	  rs.setOutput(rsoutput, false)
    end
    sleep(0.1)
  elseif event == "key" and id == 16 then
    mon.clear()
    running = false
  end
end


Client code
Spoiler

local mdmside = "back" -- Define the side of you modem
local srvid = "2" -- Define the server ID
rednet.open(mdmside)
term.clear()
term.setCursorPos(1,1)
print("Message Board Sender")
print("Type quit to stop")
while true do
  write("Enter text: ")
  message = io.read()
  if message == "quit" then
    break
  else
    rednet.send(srv, message)
 
  end
end

ArcticWinterZzZ #5
Posted 14 October 2012 - 12:45 PM
Here's two sister programs I made for an airport in my singleplayer/Hamachi world. One program is for computers to broadcast messages to the monitor, and the other will print the message to the monitor and automatically time stamp it with the in-game time.

Broadcaster

term.clear()
rednet.open("back")
term.setCursorPos(1,1)
print("Airport Board Updater")
message = io.read()
rednet.send(0, message)

Reciever

term.clear()
term.setCursorPos(1,1)
rednet.open("left")
while true do
id, message = rednet.receive()
redstone.setOutput("back", true)
local nTime = os.time()write(textutils.formatTime( nTime, false))
print (" - "..message)
print ()
sleep(1)
redstone.setOutput("back", false)
end

Of course, it must be changed a little to accomidate modem position and computer ID. Also, the reciever program must be run through the monitor, like "Monitor Right BoardGet" or something. The reciever program also has a redstone output bit, which I used to make a little 'ding dong' with two note blocks avec repeaters, and a light to even more so get people's attention.
This is the first program I made, as it was the first idea I got. I hope you peoples find it usefull.

For people who can't type, I've uploaded them both to pastebin so that, with the http api enabled, you can just type


pastebin get qgu5S6eT receiver
for the receiver and
pastebin get f6TsF190 broadcaster

 
to get the programs.