guusvanwalstijn

computercraft touch select where to go

Nov 13th, 2013
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. mouseWidth = 0
  2. mouseHeight = 0
  3.  
  4. monitor = peripheral.wrap("monitor_6")
  5.  
  6. monitor.clear()
  7.  
  8. monitor.setCursorPos(1,1)
  9.  
  10. w,h=monitor.getSize()
  11.  
  12. print(w)
  13. print(h)
  14.  
  15. monitor.setBackgroundColour((colours.lime))
  16.  
  17. monitor.setCursorPos(20,5)
  18.  
  19. monitor.write(" North  ")
  20.  
  21. monitor.setCursorPos(28,10)
  22.  
  23. monitor.write(" East ")
  24.  
  25. monitor.setCursorPos(12,10)
  26.  
  27. monitor.write(" West ")
  28.  
  29. monitor.setCursorPos(20,15)
  30.  
  31. monitor.write(" South ")
  32.  
  33. monitor.setBackgroundColour((colours.lime))
  34.  
  35. function north()
  36. rs.setOutput("back", true)
  37. sleep(1)
  38. os.reboot()
  39. end
  40.  
  41. function east()
  42. rs.setOutput("right", true)
  43. sleep(1)
  44. os.reboot()
  45. end
  46.  
  47. function south()
  48. rs.setOutput("button", true)
  49. sleep(1)
  50. os.reboot()
  51. end
  52.  
  53. function west()
  54. rs.setOutput("left", true)
  55. sleep(1)
  56. os.reboot()
  57. end
  58.  
  59. function checkClickPosition()
  60.   if mouseWidth > 12 and mouseWidth < 28 and mouseHeight == 5 then
  61.  
  62.     north()
  63.  
  64.   elseif mouseWidth > 20 and mouseWidth < 35 and mouseHeight == 10 then
  65.  
  66.     east()
  67.    
  68.     elseif mouseWidth > 12 and mouseWidth < 28 and mouseHeight == 15 then
  69.    
  70.     south()
  71.  
  72.     elseif mouseWidth > 5 and mouseWidth < 18 and mouseHeight == 10 then
  73.    
  74.     west()
  75.  
  76.   end
  77. end
  78.  
  79.  
  80. repeat
  81.  
  82.  
  83.   event,p1,p2,p3 = os.pullEvent()
  84.  
  85.  
  86.    if event=="monitor_touch" then
  87.  
  88.    
  89.      mouseWidth = p2 -- sets mouseWidth
  90.      mouseHeight = p3 -- and mouseHeight
  91.      checkClickPosition() -- this runs our function
  92.      
  93.    end
  94.    
  95. until event=="char" and p1==("x")
Advertisement
Add Comment
Please, Sign In to add comment