Guest User

CurrentMenu

a guest
Sep 15th, 2012
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 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. end
  17. function start()
  18. while true do
  19. term.clear()
  20. for i,v in ipairs(menuOptions) do
  21. if i == selected then
  22. centerText("["..v.."] ", i)
  23. else
  24. centerText(v,i)
  25. end
  26. end
  27. local id, key = os.pullEvent()
  28. if key == 208 and selected < #menuOptions then
  29. selected = selected + 1
  30. elseif key == 200 and selected > 1 then
  31. selected = selected - 1
  32. elseif key == 28 then
  33. return selected
  34. end
  35. end
  36. end
  37. x = start()
  38. print()
  39. if selected == 1 then
  40. one()
  41. end
  42. if selected == 2 then
  43. two()
  44. end
  45. if selected == 3 then
  46. three()
  47. end
Advertisement
Add Comment
Please, Sign In to add comment