Advertisement
Guest User

Untitled

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