Jump to content




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

peripheral networking

5 replies to this topic

#1 Silly511

  • New Members
  • 2 posts

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 by Silly511, 19 January 2016 - 08:02 PM.


#2 TYKUHN2

  • Members
  • 210 posts
  • LocationSomewhere in this dimension... I think.

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?)

#3 The Crazy Phoenix

  • Members
  • 136 posts
  • LocationProbably within 2 metres of my laptop.

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 by CrazyPyroEagle, 19 January 2016 - 08:37 PM.


#4 Silly511

  • New Members
  • 2 posts

Posted 19 January 2016 - 08:48 PM

I updated ComputerCraft and that fixed it. Thanks for all your help!

#5 Lupus590

  • Members
  • 1,962 posts
  • LocationUK

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 by Lupus590, 19 January 2016 - 11:00 PM.


#6 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 19 January 2016 - 11:21 PM

View PostLupus590, on 19 January 2016 - 11:00 PM, said:

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.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users