Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local ul=0
- mouseWidth = 0
- mouseHeight = 0
- monitor = peripheral.wrap("back")
- monitor.clear()
- monitor.setCursorPos(1,1)
- w,h=monitor.getSize()
- -- gets the width and the height of the monitor
- -- and stores the numbers as w and h.
- -- w and h are variables
- print(w)
- print(h)
- print(ul)
- rs.setOutput("left",false)
- rs.setOutput("right",false)
- rs.setOutput("front",false)
- rs.setOutput("bottom",false)
- monitor.setBackgroundColour((colours.red))
- -- this changes the background colour of the text
- -- to lime green.
- monitor.setCursorPos(4,2)
- -- this sets the start position for writing the 1st
- -- button on the monitor. It puts it 2 in from the
- -- left and 2 down from the top.
- monitor.write(" Requirement")
- -- this writes the word ON on the monitor. See the
- -- blank spaces before and after. These will be
- -- green. Our button is 5 letters long
- monitor.setCursorPos(4,6)
- -- this sets the next writing postition to 2 from
- -- the left and 4 down from the top. Just under
- -- the 1st button
- monitor.write(" NODE ")
- -- this writes OFF but again its 5 long in total
- -- with the spaces
- monitor.setCursorPos(4,10)
- monitor.write(" Eldritch ")
- monitor.setCursorPos(4,12)
- monitor.write("Unload Room ")
- monitor.setBackgroundColour((colours.black))
- -- now we have drawn our buttons we should set
- -- the text background colour back to black
- function countdown(c)
- for i=1,c do
- monitor.setCursorPos(1,2)
- monitor.write(" ")
- monitor.setCursorPos(1,4)
- monitor.write(" ")
- monitor.setCursorPos(1,6)
- monitor.write(" ".. c .." ")
- monitor.setCursorPos(1,10)
- monitor.write(" ")
- monitor.setCursorPos(1,12)
- monitor.write(" ")
- sleep(1)
- c = c-1
- end
- monitor.clear()
- end
- function checkClickPosition()
- if mouseWidth > 4 and mouseWidth < 13 and mouseHeight == 2 and ul == 0 then
- -- button one clicked
- rs.setOutput("right",true)
- sleep(3)
- rs.setOutput("right",false)
- sleep(5)
- countdown(5)
- rs.setOutput("top",true)
- sleep(3)
- rs.setOutput("top",false)
- sleep(1)
- rs.setOutput("bottom",false)
- sleep(5)
- ul = 1
- print(ul)
- elseif mouseWidth > 4 and mouseWidth < 13 and mouseHeight == 6 and ul == 0 then
- -- button two clicked
- rs.setOutput("left",true)
- sleep(3)
- rs.setOutput("left",false)
- sleep(5)
- countdown(5)
- rs.setOutput("top",true)
- sleep(3)
- rs.setOuput("top",false)
- sleep(1)
- rs.setOuput("bottom",false)
- sleep(5)
- ul = 1
- print(ul)
- elseif mouseWidth > 4 and mouseWidth < 13 and mousHeight == 10 and ul == 0 then
- rs.setOutput("front",true)
- sleep(3)
- rs.setOutput("front",false)
- sleep(5)
- countdown(5)
- rs.setOutput("top",true)
- sleep(3)
- rs.setOutput("top",false)
- sleep(1)
- rs.setOuput("bottom",false)
- sleep(5)
- ul=1
- print(ul)
- elseif mouseWidth > 4 and mouseWidth < 13 and mousHeight == 12 and ul == 0 then
- rs.setOutput("top",true)
- rs.setOutput("bottom",true)
- countdown(5)
- rs.setOutput("top",false)
- sleep(5)
- rs.setOuput("bottom",false)
- sleep(5)
- ul=1
- print(ul)
- elseif mouseWidth > 4 and mouseWidth < 13 and mousHeight == 12 and ul == 1 then
- countdown(7)
- print(ul)
- -- turns redstone connected to the left off
- end -- ends the if loop
- end -- ends the function
- -- this function does nothing until you write
- -- checkClickPostion(). We will be doing this below
- -- It then checks the click position and turns the
- -- lamp on if button one is clicked or turns the
- -- lamp off if button two is clicked
- -- OK. Now we need to check if a click happens
- -- we will use a repeat-until loop.
- -- In the loop we we use a os.pullEvent().
- -- an os.pullEvent() gives you different info
- -- depending on the event type. We will mainly
- -- check the "monitor_touch" event.
- -- In the second line you will see
- -- event,p1,p2,p3 = os.pullEvent()
- -- if the event is a click on the monitor it
- -- will give us 4 bits of info:
- -- event will be "monitor_touch"
- -- p1 will be the side the monitor is on (top)
- -- p2 is the width postion of the click
- -- p3 is the height postition of the click
- repeat
- -- repeat runs a loop of code.
- event,p1,p2,p3 = os.pullEvent()
- -- this line tells the computer to wait until
- -- an event happens. We are waiting for a
- -- touchscreen event
- if event=="monitor_touch" and then
- -- this checks to see if the event was a
- -- touchscreen event
- mouseWidth = p2 -- sets mouseWidth
- mouseHeight = p3 -- and mouseHeight
- checkClickPosition() -- this runs our function
- end
- -- the end of the "if loop".
- until event=="char" and p1==("x")
- -- this is the end of the "repeat loop". This will
- -- stop the repeat loop if a "char" event happens
- -- A char event means you press a character on
- -- the keyboard. This line is looking for the x key
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement