Advertisement
Guest User

Untitled

a guest
May 21st, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.15 KB | None | 0 0
  1. local ul=0
  2. mouseWidth = 0
  3. mouseHeight = 0
  4.  
  5.  
  6. monitor = peripheral.wrap("back")
  7.  
  8.  
  9. monitor.clear()
  10.  
  11. monitor.setCursorPos(1,1)
  12.  
  13. w,h=monitor.getSize()
  14. -- gets the width and the height of the monitor
  15. -- and stores the numbers as w and h.
  16. -- w and h are variables
  17. print(w)
  18. print(h)
  19. print(ul)
  20.  
  21.  
  22.  
  23. rs.setOutput("left",false)
  24. rs.setOutput("right",false)
  25. rs.setOutput("front",false)
  26. rs.setOutput("bottom",false)
  27.  
  28. monitor.setBackgroundColour((colours.red))
  29. -- this changes the background colour of the text
  30. -- to lime green.
  31.  
  32. monitor.setCursorPos(4,2)
  33. -- this sets the start position for writing the 1st
  34. -- button on the monitor. It puts it 2 in from the
  35. -- left and 2 down from the top.
  36.  
  37. monitor.write(" Requirement")
  38. -- this writes the word ON on the monitor. See the
  39. -- blank spaces before and after. These will be
  40. -- green. Our button is 5 letters long
  41.  
  42. monitor.setCursorPos(4,6)
  43. -- this sets the next writing postition to 2 from
  44. -- the left and 4 down from the top. Just under
  45. -- the 1st button
  46.  
  47. monitor.write(" NODE ")
  48. -- this writes OFF but again its 5 long in total
  49. -- with the spaces
  50. monitor.setCursorPos(4,10)
  51. monitor.write(" Eldritch ")
  52.  
  53. monitor.setCursorPos(4,12)
  54. monitor.write("Unload Room ")
  55.  
  56. monitor.setBackgroundColour((colours.black))
  57. -- now we have drawn our buttons we should set
  58. -- the text background colour back to black
  59.  
  60. function countdown(c)
  61. for i=1,c do
  62. monitor.setCursorPos(1,2)
  63. monitor.write(" ")
  64. monitor.setCursorPos(1,4)
  65. monitor.write(" ")
  66. monitor.setCursorPos(1,6)
  67. monitor.write(" ".. c .." ")
  68. monitor.setCursorPos(1,10)
  69. monitor.write(" ")
  70. monitor.setCursorPos(1,12)
  71. monitor.write(" ")
  72. sleep(1)
  73. c = c-1
  74.  
  75. end
  76. monitor.clear()
  77. end
  78.  
  79.  
  80. function checkClickPosition()
  81. if mouseWidth > 4 and mouseWidth < 13 and mouseHeight == 2 and ul == 0 then
  82. -- button one clicked
  83. rs.setOutput("right",true)
  84. sleep(3)
  85. rs.setOutput("right",false)
  86. sleep(5)
  87. countdown(5)
  88. rs.setOutput("top",true)
  89. sleep(3)
  90. rs.setOutput("top",false)
  91. sleep(1)
  92. rs.setOutput("bottom",false)
  93. sleep(5)
  94. ul = 1
  95. print(ul)
  96.  
  97.  
  98. elseif mouseWidth > 4 and mouseWidth < 13 and mouseHeight == 6 and ul == 0 then
  99. -- button two clicked
  100. rs.setOutput("left",true)
  101. sleep(3)
  102. rs.setOutput("left",false)
  103. sleep(5)
  104. countdown(5)
  105. rs.setOutput("top",true)
  106. sleep(3)
  107. rs.setOuput("top",false)
  108. sleep(1)
  109. rs.setOuput("bottom",false)
  110. sleep(5)
  111. ul = 1
  112. print(ul)
  113.  
  114.  
  115. elseif mouseWidth > 4 and mouseWidth < 13 and mousHeight == 10 and ul == 0 then
  116.  
  117. rs.setOutput("front",true)
  118. sleep(3)
  119. rs.setOutput("front",false)
  120. sleep(5)
  121. countdown(5)
  122. rs.setOutput("top",true)
  123. sleep(3)
  124. rs.setOutput("top",false)
  125. sleep(1)
  126. rs.setOuput("bottom",false)
  127. sleep(5)
  128. ul=1
  129. print(ul)
  130.  
  131. elseif mouseWidth > 4 and mouseWidth < 13 and mousHeight == 12 and ul == 0 then
  132.  
  133. rs.setOutput("top",true)
  134. rs.setOutput("bottom",true)
  135. countdown(5)
  136. rs.setOutput("top",false)
  137. sleep(5)
  138. rs.setOuput("bottom",false)
  139. sleep(5)
  140. ul=1
  141. print(ul)
  142.  
  143. elseif mouseWidth > 4 and mouseWidth < 13 and mousHeight == 12 and ul == 1 then
  144. countdown(7)
  145. print(ul)
  146.  
  147. -- turns redstone connected to the left off
  148. end -- ends the if loop
  149. end -- ends the function
  150.  
  151. -- this function does nothing until you write
  152. -- checkClickPostion(). We will be doing this below
  153. -- It then checks the click position and turns the
  154. -- lamp on if button one is clicked or turns the
  155. -- lamp off if button two is clicked
  156.  
  157. -- OK. Now we need to check if a click happens
  158. -- we will use a repeat-until loop.
  159. -- In the loop we we use a os.pullEvent().
  160. -- an os.pullEvent() gives you different info
  161. -- depending on the event type. We will mainly
  162. -- check the "monitor_touch" event.
  163.  
  164. -- In the second line you will see
  165. -- event,p1,p2,p3 = os.pullEvent()
  166. -- if the event is a click on the monitor it
  167. -- will give us 4 bits of info:
  168. -- event will be "monitor_touch"
  169. -- p1 will be the side the monitor is on (top)
  170. -- p2 is the width postion of the click
  171. -- p3 is the height postition of the click
  172.  
  173.  
  174.  
  175. repeat
  176. -- repeat runs a loop of code.
  177.  
  178. event,p1,p2,p3 = os.pullEvent()
  179. -- this line tells the computer to wait until
  180. -- an event happens. We are waiting for a
  181. -- touchscreen event
  182.  
  183. if event=="monitor_touch" and then
  184. -- this checks to see if the event was a
  185. -- touchscreen event
  186.  
  187. mouseWidth = p2 -- sets mouseWidth
  188. mouseHeight = p3 -- and mouseHeight
  189. checkClickPosition() -- this runs our function
  190. end
  191. -- the end of the "if loop".
  192.  
  193.  
  194. until event=="char" and p1==("x")
  195. -- this is the end of the "repeat loop". This will
  196. -- stop the repeat loop if a "char" event happens
  197. -- A char event means you press a character on
  198. -- the keyboard. This line is looking for the x key
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement