Guest User

MenuOption

a guest
Sep 14th, 2012
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. function one()
  2. print("Hello")
  3. end
  4. function two()
  5. print("Hey")
  6. end
  7. function three()
  8. print("Hi")
  9. end
  10. local menuOptions = {"1", "2", "3"}
  11. local termX, termY = term.getSize()
  12. local selected = 1
  13. function centerText(text, termY)
  14. term.setCursorPos(termX/2-#text/2,termY)
  15. term.write(text)
  16. return true
  17. end
  18. function start()
  19. while true do
  20. term.clear()
  21. for i,v in ipairs(menuOptions) do
  22. if i == selected then
  23. centerText("[ "..v.."] ", i)
  24. else
  25. centerText(v,i)
  26. end
  27. end
  28. local id, key = os.pullEvent()
  29. if key == 208 and selected < #menuOptions then
  30. selected = selected + 1
  31. elseif key == 200 and selected > 1 then
  32. selected = selected - 1
  33. elseif key == 28 then
  34. return selected
  35. end
  36. end
  37. end
  38. x = start()
  39. print()
  40. if selected == 1 then
  41. one()
  42. end
  43. if selected == 2 then
  44. two()
  45. end
  46. if selected == 3 then
  47. three()
  48. end
Advertisement
Add Comment
Please, Sign In to add comment