Advertisement
Guest User

Untitled

a guest
May 21st, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.68 KB | None | 0 0
  1. ul=1
  2. mouseWidth = 0
  3. mouseHeight = 0
  4. -- this creates two variables called mouseWidth
  5. -- and mouseHeight and sets them to 0. We will
  6. -- use them later
  7.  
  8. monitor = peripheral.wrap("back")
  9. -- you need this line! It tells the computer
  10. -- the monitor is on top. Change it if you want
  11. -- the monitor on a different side of the computer
  12.  
  13. monitor.clear()
  14. -- this clears the monitor screen
  15.  
  16. monitor.setCursorPos(1,1)
  17. -- this sets the cursor position to the top left
  18. -- corner of the monitor
  19.  
  20. w,h=monitor.getSize()
  21. -- gets the width and the height of the monitor
  22. -- and stores the numbers as w and h.
  23. -- w and h are variables
  24. print(w)
  25. print(h)
  26. -- prints the w and h to the computer screen.
  27. -- You can see the monitor width is 7, height is 5
  28. -- It starts in the top left corner like a book.
  29.  
  30.  
  31. -- Now to draw the two buttons
  32. -- Im english so I write colour but you can change
  33. -- it to color. It works the same.
  34. function GuiDraw()
  35. rs.setOutput("left",false)
  36. rs.setOutput("right",false)
  37. rs.setOutput("front",false)
  38. rs.setOutput("bottom",false)
  39.  
  40. monitor.setBackgroundColour((colours.red))
  41. -- this changes the background colour of the text
  42. -- to lime green.
  43.  
  44. monitor.setCursorPos(4,2)
  45. -- this sets the start position for writing the 1st
  46. -- button on the monitor. It puts it 2 in from the
  47. -- left and 2 down from the top.
  48.  
  49. monitor.write(" Requirement")
  50. -- this writes the word ON on the monitor. See the
  51. -- blank spaces before and after. These will be
  52. -- green. Our button is 5 letters long
  53.  
  54. monitor.setCursorPos(4,5)
  55. -- this sets the next writing postition to 2 from
  56. -- the left and 4 down from the top. Just under
  57. -- the 1st button
  58.  
  59. monitor.write(" NODE ")
  60. -- this writes OFF but again its 5 long in total
  61. -- with the spaces
  62. monitor.setCursorPos(4,9)
  63. monitor.write(" Eldritch ")
  64.  
  65. monitor.setCursorPos(4,12)
  66. monitor.write("Unload Room ")
  67.  
  68. monitor.setBackgroundColour((colours.black))
  69. -- now we have drawn our buttons we should set
  70. -- the text background colour back to black
  71. end
  72. GuiDraw()
  73.  
  74. -- Now we need to check if the button is clicked
  75.  
  76. -- First we are going to create a function called
  77. -- checkClickPosition(). A function will not run
  78. -- until you ask for it.
  79.  
  80. -- We know the first button starts at 2 from the
  81. -- top and 2 from the left. We also know it is 5
  82. -- spaces long. This means the button ends
  83. -- at width 7
  84.  
  85. -- We will be told which width and
  86. -- height the click happened at.
  87. -- If the width position is greater than 1 AND
  88. -- less than 8 we have clicked somewhere between
  89. -- 2 and 7.
  90.  
  91. -- If this is true we can then check the height
  92. -- position. Button one is at height 2 and button
  93. -- two is at height 4.
  94.  
  95. -- This means that if the width is greater than 1
  96. -- AND the width is less than 8 AND the height
  97. -- equals 2 we have clicked button 1
  98.  
  99. -- If the the width is greater than 1 AND the width
  100. -- is less than 8 AND the height equals 4 we have
  101. -- clicked button 2
  102.  
  103. -- now to write this as a function
  104. -- Functions are written like this
  105.  
  106. -- function exampleFunction()
  107. -- print("Hello")
  108. -- sleep(10)
  109. -- print("Goodbye")
  110. -- end
  111.  
  112. -- Now when you write exampleFunction() the program
  113. -- will print hello, sleep for 10 ticks and then
  114. -- print Goodbye.
  115. -- This is useful for making your programs easier
  116. -- to understand
  117. function countdown(c)
  118. for i=1,c do
  119. monitor.setCursorPos(7,2)
  120. monitor.write(" ")
  121. monitor.setCursorPos(7,4)
  122. monitor.write(" ")
  123. monitor.setCursorPos(7,6)
  124. monitor.write(" ".. c .." ")
  125. monitor.setCursorPos(7,8)
  126. monitor.write(" ")
  127. monitor.setCursorPos(7,10)
  128. monitor.write(" ")
  129. sleep(1)
  130. c = c-1
  131.  
  132. end
  133. monitor.clear()
  134. GuiDraw()
  135. end
  136. function countdown2(c)
  137. for i=1,c do
  138. monitor.setCursorPos(7,2)
  139. monitor.write(" UNLOAD ")
  140. monitor.setCursorPos(7,4)
  141. monitor.write(" ROOM ")
  142. monitor.setCursorPos(7,6)
  143. monitor.write(" ".. c .." ")
  144. monitor.setCursorPos(7,8)
  145. monitor.write(" ")
  146. monitor.setCursorPos(7,10)
  147. monitor.write(" ")
  148. sleep(1)
  149. c = c-1
  150.  
  151. end
  152. monitor.clear()
  153. GuiDraw()
  154. end
  155.  
  156. function checkClickPosition()
  157. if mouseWidth > 4 and mouseWidth < 13 and mouseHeight == 2 and ul ~= -1 then
  158. -- button one clicked
  159. rs.setOutput("right",true)
  160. sleep(3)
  161. rs.setOutput("right",false)
  162. sleep(5)
  163. countdown(5)
  164. rs.setOutput("top",true)
  165. sleep(3)
  166. rs.setOutput("top",false)
  167. rs.setOutput("bottom",true)
  168. sleep(1)
  169. rs.setOutput("bottom",false)
  170. sleep(5)
  171. ul=-1
  172.  
  173.  
  174. elseif mouseWidth > 4 and mouseWidth < 13 and mouseHeight == 5 and ul ~= -1 then
  175. -- button two clicked
  176. rs.setOutput("left",true)
  177. sleep(3)
  178. rs.setOutput("left",false)
  179. sleep(5)
  180. countdown(5)
  181. rs.setOuput("top",true)
  182. sleep(3)
  183. rs.setOuput("top",false)
  184. rs.setOutput("bottom",true)
  185. sleep(1)
  186. rs.setOuput("bottom",false)
  187. sleep(5)
  188. ul=-1
  189.  
  190. elseif mouseWidth > 4 and mouseWidth < 13 and mousHeight == 9 and ul ~= -1 then
  191.  
  192. rs.setOutput("front",true)
  193. sleep(3)
  194. rs.setOutput("front",false)
  195. sleep(5)
  196. countdown(5)
  197. rs.setOutput("top",true)
  198. sleep(3)
  199. rs.setOutput("top",false)
  200. rs.setOutput("bottom",true)
  201. sleep(1)
  202. rs.setOuput("bottom",false)
  203. sleep(5)
  204. ul=-1
  205.  
  206. elseif mouseWidth > 4 and mouseWidth < 13 and mousHeight == 12 and ul == -1 then
  207.  
  208.  
  209. rs.setOutput("top",true)
  210. rs.setOutput("bottom",true)
  211. countdown(5)
  212. rs.setOutput("top",false)
  213. sleep(5)
  214. rs.setOuput("bottom",false)
  215. sleep(5)
  216. ul=1
  217.  
  218. else
  219. countdown2(5)
  220.  
  221. -- turns redstone connected to the left off
  222. end -- ends the if loop
  223. end -- ends the function
  224.  
  225. -- this function does nothing until you write
  226. -- checkClickPostion(). We will be doing this below
  227. -- It then checks the click position and turns the
  228. -- lamp on if button one is clicked or turns the
  229. -- lamp off if button two is clicked
  230.  
  231. -- OK. Now we need to check if a click happens
  232. -- we will use a repeat-until loop.
  233. -- In the loop we we use a os.pullEvent().
  234. -- an os.pullEvent() gives you different info
  235. -- depending on the event type. We will mainly
  236. -- check the "monitor_touch" event.
  237.  
  238. -- In the second line you will see
  239. -- event,p1,p2,p3 = os.pullEvent()
  240. -- if the event is a click on the monitor it
  241. -- will give us 4 bits of info:
  242. -- event will be "monitor_touch"
  243. -- p1 will be the side the monitor is on (top)
  244. -- p2 is the width postion of the click
  245. -- p3 is the height postition of the click
  246.  
  247.  
  248.  
  249. repeat
  250. -- repeat runs a loop of code.
  251.  
  252. event,p1,p2,p3 = os.pullEvent()
  253. -- this line tells the computer to wait until
  254. -- an event happens. We are waiting for a
  255. -- touchscreen event
  256.  
  257. if event=="monitor_touch" then
  258. -- this checks to see if the event was a
  259. -- touchscreen event
  260.  
  261. mouseWidth = p2 -- sets mouseWidth
  262. mouseHeight = p3 -- and mouseHeight
  263. checkClickPosition() -- this runs our function
  264.  
  265. end
  266. -- the end of the "if loop".
  267.  
  268.  
  269. until event=="char" and p1==("x")
  270. -- this is the end of the "repeat loop". This will
  271. -- stop the repeat loop if a "char" event happens
  272. -- A char event means you press a character on
  273. -- the keyboard. This line is looking for the x key
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement