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

How do I write the same information to all monitors on a network?

Started by Silly511, 19 January 2016 - 06:58 PM
Silly511 #1
Posted 19 January 2016 - 07:58 PM
I am making a clock program that shows real-world time on all connected monitors. The only problem is that it shows the time on all monitors touching the computer, not all monitors on the wired modem network. How do I get it to show the time on all monitors? Here is my code:


local monitors = {peripheral.find("monitor")}

for i=1,#monitors do
  monitors[i].clear()
  monitors[i].setTextScale(3.5)
end

local function centerText(text)
  for i=1,#monitors do
    local x,y = monitors[i].getSize()
    local x2,y2 = monitors[i].getCursorPos()
    monitors[i].setCursorPos(math.ceil((x / 2) - (text:len() / 2)), y2)
    monitors[i].write(text)
  end
end

if (fs.exists("/timezone")) then
  
else
print("Enter TimeZone:")
    local filewrite = fs.open("/timezone","w")
filewrite.writeLine(read())
    filewrite.close()

    local start = fs.open("/startup","w")
    start.writeLine('shell.run("time")')
    start.close()
end
    
fileread = fs.open("/timezone","r")
local timezone = fileread.readAll()
fileread.close()

while true do
  
  if (redstone.getInput("right")) then
    centerText(http.get("http://www.timeapi.org/"..timezone.."/in+one+hour?format=%20%25l:%25M%20%25p").readAll())
  else
    centerText(http.get("http://www.timeapi.org/"..timezone.."/now?format=%20%25l:%25M%20%25p").readAll())
  end

  sleep(0.1)
end
Edited on 19 January 2016 - 07:02 PM
TYKUHN2 #2
Posted 19 January 2016 - 08:29 PM
I suspect this may be a bug. Are you using the latest version? Also test by grabbing every peripheral (peripheral.getNames()) and filtering through it with some method (like a pcall maybe?)
The Crazy Phoenix #3
Posted 19 January 2016 - 08:36 PM
Make sure that the other monitors are connected to the controlling computer and that you have enabled their wired modems (right click to turn modem red).

Also, you shouldn't need a pcall, just check the peripheral type after each iteration.
Edited on 19 January 2016 - 07:37 PM
Silly511 #4
Posted 19 January 2016 - 08:48 PM
I updated ComputerCraft and that fixed it. Thanks for all your help!
Lupus590 #5
Posted 19 January 2016 - 11:00 PM
related question: http://www.computerc...tiple-monitors/

there is a program on the forums which does this, I can't find it though
Edited on 19 January 2016 - 10:00 PM
Bomb Bloke #6
Posted 19 January 2016 - 11:21 PM
related question: http://www.computerc...tiple-monitors/

there is a program on the forums which does this, I can't find it though

You're probably thinking of this one.