Advertisement
abstract_abstract

monitor.lua

Oct 14th, 2024 (edited)
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.44 KB | None | 0 0
  1. local hostIDs = {32, 72, 95}
  2. local teleports = {}
  3. local textScale = 0.9
  4.  
  5.  
  6. local function startOperations()
  7.     rednet.open("left")
  8.     rednet.send(126, "", "dns_list")
  9.     local senderID, message, protocol = rednet.receive("dns_list_response")
  10.     teleports = textutils.unserialize(message)
  11.     for k, v in pairs(teleports) do
  12.         print(k, v)
  13.     end
  14. end
  15.  
  16.  
  17. local function display()
  18.     local monitor = peripheral.wrap("top")
  19.     monitor.setTextScale(textScale)
  20.     monitor.setBackgroundColour(colors.blue)
  21.     monitor.clear()
  22.     monitor.setCursorPos(1, 1)
  23.     local function dispNewLine()
  24.         local x, y = monitor.getCursorPos()
  25.         monitor.setCursorPos(1, y + 1)
  26.     end
  27.  
  28.     local function displayLine()
  29.         local width = monitor.getSize()
  30.         for i = 1, width do
  31.             monitor.write("-")
  32.         end
  33.         dispNewLine()
  34.     end
  35.  
  36.     for k, v in pairs(teleports) do
  37.         displayLine()
  38.         monitor.write(k .. " " .. v)
  39.         dispNewLine()
  40.         displayLine()
  41.     end
  42. end
  43.  
  44.  
  45. local function work()
  46.     while true do
  47.         local event, side, x, y = os.pullEvent("monitor_touch")
  48.         local btnClicked = math.ceil(y / 3)
  49.         print(event.."; x="..x.."; y="..y)
  50.         print("Button clicked = "..btnClicked)
  51.         print(teleports[btnClicked])
  52.         if btnClicked <= #teleports and btnClicked > 0 then
  53.    
  54.         end
  55.     end
  56. end
  57.  
  58.  
  59. startOperations()
  60. display()
  61. work()
  62.  
  63.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement