Advertisement
Guest User

newstart

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