fi5hii

Untitled

May 11th, 2024
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. -- Load the required components
  2. local monitor = peripheral.find("monitor", function(name) return name == "monitor_2" end) -- Monitor peripheral named monitor_2
  3. local modem = peripheral.find("modem") -- Modem peripheral
  4. local redstoneSide = "left" -- Define the side where the redstone is connected
  5.  
  6. -- Function to display line 1 from create_target_1 on monitor_2
  7. function displayLine()
  8. -- Get the line 1 from create_target_1
  9. local line = peripheral.call("create_target_1", "getLine", 1)
  10.  
  11. -- Clear the monitor
  12. monitor.clear()
  13.  
  14. -- Set cursor position at (1,1)
  15. monitor.setCursorPos(1, 1)
  16.  
  17. -- Display the line on monitor
  18. monitor.write(line)
  19.  
  20. -- Display clickable text below the line
  21. monitor.setCursorPos(1, 3)
  22. monitor.setTextColor(colors.green) -- Set text color to green
  23. monitor.write("ON")
  24. monitor.setTextColor(colors.red) -- Set text color to red
  25. monitor.write(" OFF")
  26. monitor.setTextColor(colors.white)
  27.  
  28. -- Return the hitbox coordinates for ON and OFF texts
  29. return 1, 2, 5, 8 -- x1, x2, x3, x4
  30. end
  31.  
  32. -- Function to handle monitor touch events
  33. function handleTouch(x, y)
  34. local onX1, onX2, offX1, offX2 = displayLine()
  35.  
  36. -- Check if touch is within the clickable area for ON
  37. if y == 3 and x >= onX1 and x <= onX2 then
  38. -- Send a message to computer_2 to activate the ON signal
  39. modem.transmit(2, 1, "ON")
  40. end
  41.  
  42. -- Check if touch is within the clickable area for OFF
  43. if y == 3 and x >= offX1 and x <= offX2 then
  44. -- Send a message to computer_2 to activate the OFF signal
  45. modem.transmit(2, 1, "OFF")
  46. end
  47. end
  48.  
  49. -- Main function
  50. function main()
  51. while true do
  52. -- Wait for touch event
  53. local event, side, x, y = os.pullEvent("monitor_touch")
  54. handleTouch(x, y)
  55. end
  56. end
  57.  
  58. -- Run the main function
  59. main()
  60.  
Advertisement
Add Comment
Please, Sign In to add comment