Advertisement
daandecomputer

Daanos menu2

Jan 6th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function one()
  2. os.shutdown()
  3. end
  4. function two()
  5. shell.run("pastebin get vgmvimJB menu3")
  6. shell.run("menu3")
  7. end
  8. function three()
  9. shell.run("menu")
  10. end
  11. function four()
  12. os.shutdown()
  13. end
  14. local menuOptions = {"shutdown", "More", "terug"}
  15. local termX, termY = term.getSize()
  16. local selected = 1
  17. local strSeperator = string.rep(" ",5)
  18. function centerText(text, termY)
  19. term.setCursorPos(termX/2-#text/2, termY)
  20. term.write(text)
  21. end
  22. function start()
  23. while true do
  24. term.clear()
  25. local strMenuLine = "|"
  26. for i,v in ipairs(menuOptions) do
  27. if i == selected then
  28. strMenuLine = strMenuLine..strSeperator.."["..v.."]"
  29. else
  30. strMenuLine = strMenuLine..strSeperator.." "..v.." "
  31. end
  32. strMenuLine = strMenuLine..strSeperator.."|"
  33. end
  34. centerText("+"..string.rep("-",(#strMenuLine-2)).."+",1)
  35. centerText(strMenuLine,2)
  36. centerText("+"..string.rep("-",(#strMenuLine-2)).."+",3)
  37. local id, key = os.pullEvent()
  38. if id == "key" then
  39. if key == 205 then
  40. selected = selected + 1
  41. if selected > #menuOptions then
  42. selected = 1
  43. end
  44. elseif key == 203 then
  45. selected = selected - 1
  46. if selected < 1 then
  47. selected = #menuOptions
  48. end
  49. elseif key == 28 then
  50. return selected
  51. end
  52. end
  53. end
  54. end
  55. x = start()
  56. print()
  57. if x == 1 then
  58. one()
  59. end
  60. if x == 2 then
  61. two()
  62. end
  63. if x == 3 then
  64. three()
  65. end
  66. if x == 4 then
  67. four()
  68. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement