Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Declare a table with the buttons that will be printed,
- -- with it's own Text Colour and Background Colour and
- -- unique x and y values.
- mon = peripheral.wrap("right")
- mon1 = peripheral.wrap("top")
- mon.setTextScale(0.5)
- mon1.setTextColor(colors.black)
- mon1.setBackgroundColor(colors.yellow)
- mon1.clear()
- mon.setBackgroundColor(colors.yellow)
- mon.clear()
- t = {
- {text = "1 Rezept", x = 4, y = 1, txtCol = colours.yellow, bgCol = colors.black},
- {text = "2 Rezepte", x = 4, y = 3, txtCol = colours.yellow, bgCol = colors.black},
- {text = "3 Rezepte", x = 4, y = 5, txtCol = colours.yellow, bgCol = colors.black},
- {text = "4 Rezepte", x = 4, y = 7, txtCol = colours.yellow, bgCol = colors.black},
- {text = "5 Rezepte", x = 4, y = 9, txtCol = colours.yellow, bgCol = colors.black},
- }
- function writeButtons(_table)
- for i, v in pairs(_table) do
- mon.setCursorPos(v.x, v.y)
- mon.setTextColour(v.txtCol)
- mon.setBackgroundColour(v.bgCol)
- mon.write(v.text)
- end
- return false, nil
- end
- function isValidClick(_table, mx, my)
- for i, v in pairs(_table) do
- if mx >= v.x and mx <= (v.x + #v.text) and my == v.y then
- return true, v.text
- end
- end
- end
- function redDown(k)
- while k>0 do
- redstone.setOutput("bottom", true)
- sleep(0.2)
- redstone.setOutput("bottom", false)
- k = k-1
- end
- end
- function countDown()
- i = 35
- while i>0 do
- mon1.setCursorPos(1,2)
- mon1.write("Rezept(e)")
- mon1.setCursorPos(1,3)
- mon1.write("verfügbar")
- mon1.setCursorPos(1,4)
- mon1.write("in:")
- mon1.setCursorPos(17,3)
- mon1.write(i)
- mon1.setCursorPos(17,3)
- i = i-1
- sleep(1)
- end
- mon1.clear()
- end
- writeButtons(t)
- while true do
- _, but, x, y = os.pullEvent("monitor_touch")
- bClick, option = isValidClick(t, x, y)
- if bClick then
- -- Yes, it's a valid click. Now let's do something with the returned text 'option'
- if option == "1 Rezept" then
- i = 3
- redDown(3)
- countDown()
- elseif option == "2 Rezepte" then
- redDown()
- sleep(1)
- redDown()
- countDown()
- elseif option == "3 Rezepte" then
- redDown()
- sleep(1)
- redDown()
- sleep(1)
- redDown()
- countDown()
- elseif option == "4 Rezepte" then
- redDown()
- sleep(1)
- redDown()
- sleep(1)
- redDown()
- sleep(1)
- redDown()
- countDown()
- elseif option == "5 Rezepte" then
- redDown()
- sleep(1)
- redDown()
- sleep(1)
- redDown()
- sleep(1)
- redDown()
- sleep(1)
- redDown()
- countDown()
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment