Advertisement
sosochka

messenger.lua

Dec 20th, 2022 (edited)
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.92 KB | None | 0 0
  1.  
  2. local function syncMessages()
  3.     local width, height = term.getSize()
  4.     while  true do
  5.         local sender, message = rednet.receive()
  6.         if sender then
  7.             term.setCursorPos(1, height)
  8.             print(message)
  9.             term.write(string.rep("-", width))
  10.             term.scroll(1)
  11.         end
  12.     end
  13. end
  14.  
  15. local function mainLoop()
  16.     local width, height = term.getSize()
  17.     while true do
  18.         term.setCursorPos(1, height)
  19.         term.write(string.rep("-", width))
  20.         term.scroll(1)
  21.  
  22.         term.setCursorPos(1, height)
  23.         local message = io.read()
  24.         term.setCursorPos(1, height-1)
  25.         print(message)
  26.        
  27.         rednet.broadcast(message)
  28.     end
  29. end
  30.  
  31.  
  32. term.clear()
  33. local modem = peripheral.find("modem")
  34.  
  35. if modem then
  36.     rednet.open("back")
  37.     parallel.waitForAny(syncMessages, mainLoop)
  38. else
  39.     print("Modem not found, no service")
  40. end
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement