Advertisement
YK7942

Monitor

Jan 9th, 2017
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.20 KB | None | 0 0
  1. --[[TODO LIST
  2. 01 DONE Catch errors when no modem/monitor are found. Currently it just crashes the program
  3. 02 TODO Add instructions
  4. ]]
  5.  
  6. function Main()
  7.     local netPos = FindPeripheral("modem")
  8.     if netPos == null then print("Error: No modem detected.") sleep(5) break end
  9.     Display("Running 'Monitor'")
  10.     rednet.open(netPos)
  11.     while true do
  12.         local ID,message = rednet.receive()
  13.         print(message)
  14.         Display(message,monPos)
  15.         sleep(1)
  16.     end
  17.     rednet.close(netPos)
  18. end
  19.  
  20. function Display(text)
  21.     local monPos = FindPeripheral("monitor")
  22.     if monPos == null then print("Error: No monitor detected.") sleep(5) break end
  23.     local mon = peripheral.wrap(monPos)
  24.     mon.scroll(-1) 
  25.     mon.setCursorPos(1,1)
  26.     mon.write(text)
  27. end
  28.  
  29. function FindPeripheral(peripheralType)
  30.     if peripheral.getType("right") == peripheralType then return "right" end
  31.     if peripheral.getType("left") == peripheralType then return "left" end
  32.     if peripheral.getType("top") == peripheralType then return "top" end
  33.     if peripheral.getType("bottom") == peripheralType then return "bottom" end
  34.     if peripheral.getType("front") == peripheralType then return "front" end
  35.     if peripheral.getType("back") == peripheralType then return "back" end
  36. end
  37.  
  38. Main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement