Advertisement
Guest User

Untitled

a guest
May 21st, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.82 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.setBackgroundColour((colours.black))
  54. -- now we have drawn our buttons we should set
  55. -- the text background colour back to black
  56.  
  57. function countdown(c)
  58. for i=1,c do
  59. monitor.setCursorPos(1,2)
  60. monitor.write(" ")
  61. monitor.setCursorPos(1,4)
  62. monitor.write(" ")
  63. monitor.setCursorPos(1,6)
  64. monitor.write(" ".. c .." ")
  65. monitor.setCursorPos(1,10)
  66. monitor.write(" ")
  67. monitor.setCursorPos(1,12)
  68. monitor.write(" ")
  69. sleep(1)
  70. c = c-1
  71.  
  72. end
  73. monitor.clear()
  74. end
  75.  
  76.  
  77. function checkClickPosition()
  78. if mouseWidth > 4 and mouseWidth < 13 and mouseHeight == 2 and ul == 0 then
  79. -- button one clicked
  80. rs.setOutput("right",true)
  81. sleep(3)
  82. rs.setOutput("right",false)
  83. sleep(5)
  84. countdown(5)
  85. rs.setOutput("top",true)
  86. sleep(3)
  87. rs.setOutput("top",false)
  88. sleep(1)
  89. rs.setOutput("bottom",false)
  90. sleep(5)
  91. ul = 1
  92. print(ul)
  93.  
  94.  
  95. elseif mouseWidth > 4 and mouseWidth < 13 and mouseHeight == 6 and ul == 0 then
  96. -- button two clicked
  97. rs.setOutput("left",true)
  98. sleep(3)
  99. rs.setOutput("left",false)
  100. sleep(5)
  101. countdown(5)
  102. rs.setOutput("top",true)
  103. sleep(3)
  104. rs.setOuput("top",false)
  105. sleep(1)
  106. rs.setOuput("bottom",false)
  107. sleep(5)
  108. ul = 1
  109. print(ul)
  110.  
  111.  
  112. elseif mouseWidth > 4 and mouseWidth < 13 and mousHeight == 10 and ul == 0 then
  113.  
  114. rs.setOutput("front",true)
  115. sleep(3)
  116. rs.setOutput("front",false)
  117. sleep(5)
  118. countdown(5)
  119. rs.setOutput("top",true)
  120. sleep(3)
  121. rs.setOutput("top",false)
  122. sleep(1)
  123. rs.setOuput("bottom",false)
  124. sleep(5)
  125. ul=1
  126. print(ul)
  127.  
  128. elseif mouseWidth > 4 and mouseWidth < 13 and mousHeight == 10 and ul == 1 then
  129. countdown(7)
  130. print(ul)
  131.  
  132. -- turns redstone connected to the left off
  133. end -- ends the if loop
  134. end -- ends the function
  135.  
  136. -- this function does nothing until you write
  137. -- checkClickPostion(). We will be doing this below
  138. -- It then checks the click position and turns the
  139. -- lamp on if button one is clicked or turns the
  140. -- lamp off if button two is clicked
  141.  
  142. -- OK. Now we need to check if a click happens
  143. -- we will use a repeat-until loop.
  144. -- In the loop we we use a os.pullEvent().
  145. -- an os.pullEvent() gives you different info
  146. -- depending on the event type. We will mainly
  147. -- check the "monitor_touch" event.
  148.  
  149. -- In the second line you will see
  150. -- event,p1,p2,p3 = os.pullEvent()
  151. -- if the event is a click on the monitor it
  152. -- will give us 4 bits of info:
  153. -- event will be "monitor_touch"
  154. -- p1 will be the side the monitor is on (top)
  155. -- p2 is the width postion of the click
  156. -- p3 is the height postition of the click
  157.  
  158.  
  159.  
  160. repeat
  161. -- repeat runs a loop of code.
  162.  
  163. event,p1,p2,p3 = os.pullEvent()
  164. -- this line tells the computer to wait until
  165. -- an event happens. We are waiting for a
  166. -- touchscreen event
  167.  
  168. if event=="monitor_touch" and then
  169. -- this checks to see if the event was a
  170. -- touchscreen event
  171.  
  172. mouseWidth = p2 -- sets mouseWidth
  173. mouseHeight = p3 -- and mouseHeight
  174. checkClickPosition() -- this runs our function
  175. end
  176. -- the end of the "if loop".
  177.  
  178.  
  179. until event=="char" and p1==("x")
  180. -- this is the end of the "repeat loop". This will
  181. -- stop the repeat loop if a "char" event happens
  182. -- A char event means you press a character on
  183. -- the keyboard. This line is looking for the x key
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement