bobmarley12345

Computercraft Touchscreen

Oct 16th, 2020 (edited)
64
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- carrot heheheehheehehe
  2. -- you have to know how to use CC to use this..... lol
  3. MonitorSide = "bottom"
  4. Monitor = peripheral.wrap(MonitorSide)
  5. LatestMessage = ""
  6. TouchX = 0
  7. TouchY = 0
  8.  
  9. -- waits until a monitor_touch event occours then sets the coords
  10. function WaitForMonitorTouch()
  11.     local event, side, x, y = os.pullEvent("monitor_touch")
  12.     TouchX = x
  13.     TouchY = y
  14.     LatestMessage = "monTouch"
  15. end
  16.  
  17. -- Called when a player right clicks/touches a monitor
  18. function MonitorTouched()
  19.     local x = TouchX
  20.     local y = TouchY
  21.  
  22.     -- add code with x, y coords of where the monitor was touched
  23.  
  24.     return
  25. end
  26.  
  27. -- Main Loop code
  28. function LoopCode()
  29.     while true do
  30.  
  31.         -- Code to be looped
  32.  
  33.         os.sleep(1)
  34.     end
  35. end
  36.  
  37. -- main function run first
  38. function Main()
  39.     while true do
  40.         -- runs these 2 functions at the same time... i think
  41.         -- and when one of them returns, the other does too and
  42.         -- then the if statement below is executed. then goes back
  43.         -- to the start running the parallel, etc.
  44.         parallel.waitForAny(LoopCode, WaitForMonitorTouch)
  45.  
  46.         -- dont technically need this if statement, you could just
  47.         -- run the MonitorTouched function, but eh. this just ensures
  48.         -- that the monitor was 100% touched
  49.         if (LatestMessage == "monTouch") then
  50.             LatestMessage = "none"
  51.             MonitorTouched()
  52.         end
  53.     end
  54. end
  55.  
  56. Main()
RAW Paste Data