Advertisement
abstract_abstract

Monitor

Oct 9th, 2024
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.13 KB | None | 0 0
  1. local hostIDs = {32, 72, 95}
  2. local teleports = {}
  3. local textScale = 0.9
  4.  
  5. function startOperations()
  6.     local file = fs.open("list.txt", "r")
  7.     local text = file.readAll()
  8.     file.close()
  9.  
  10.     for pairText in string.gmatch(text, "([^;]+)") do
  11.         local pair = {}
  12.         for textInPair in string.gmatch(pairText, "([^-]+)") do
  13.             table.insert(pair, textInPair)
  14.         end
  15.         table.insert(teleports, pair)
  16.     end
  17.  
  18.     for k, v in pairs(teleports) do
  19.         print(k, v[1], v[2])
  20.     end
  21.     rednet.open("right")
  22.     print("rednet opened")
  23. end
  24.  
  25.  
  26. function display()
  27.     monit = peripheral.wrap("top")
  28.     monit.setTextScale(textScale)
  29.     monit.setBackgroundColour(colors.black)
  30.     monit.clear()
  31.     monit.setCursorPos(1, 1)
  32.     local function dispNewLine()
  33.         local x, y = monit.getCursorPos()
  34.         monit.setCursorPos(1, y + 1)
  35.     end
  36.  
  37.     local function displayLine()
  38.         local width = monit.getSize()
  39.         for i = 1, width do
  40.             monit.write("-")
  41.         end
  42.         dispNewLine()
  43.     end
  44.  
  45.     for k, v in pairs(teleports) do
  46.         displayLine()
  47.         monit.write(k .. " " .. v[1] .. " " .. v[2])
  48.         dispNewLine()
  49.         displayLine()
  50.     end
  51. end
  52.  
  53. function work()
  54.     while true do
  55.         local event, side, x, y = os.pullEvent("monitor_touch")
  56.         local btnClicked = math.ceil(y / 3)
  57.         print(event.."; x="..x.."; y="..y)
  58.         print("Button clicked = "..btnClicked)
  59.         if btnClicked <= #teleports and btnClicked > 0 then
  60.             print(teleports[btnClicked][1] .. " -> " .. teleports[btnClicked][2])
  61.             local hostIndex = math.ceil(btnClicked / 5)
  62.             local targetHostID = hostIDs[hostIndex]
  63.             print("try to send side to host")
  64.             local result = rednet.send(targetHostID, teleports[btnClicked][1], "teleportSystem1")
  65.             print("Is it successful? -> "..tostring(result))
  66.         else
  67.             print("This is not button")
  68.         end
  69.         print("end of operation")
  70.         print("")
  71.     end
  72. end
  73.  
  74.  
  75. function start()
  76.     startOperations()
  77.     display()
  78.     work()
  79. end
  80.  
  81. start()
  82.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement