Guest User

Untitled

a guest
Sep 17th, 2012
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.26 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. local strSeperator = string.rep(" ",5)
  14. function centerText(text, termY)
  15. term.setCursorPos(termX/2-#text/2, termY)
  16. term.write(text)
  17. end
  18. function start()
  19. while true do
  20.   term.clear()
  21.   local strMenuLine = "|"
  22.   for i,v in ipairs(menuOptions) do
  23.    if i == selected then
  24.     strMenuLine = strMenuLine..strSeperator.."["..v.."]"
  25.    else
  26.     strMenuLine = strMenuLine..strSeperator.." "..v.." "
  27.    end
  28.    strMenuLine = strMenuLine..strSeperator.."|"
  29.   end
  30.   centerText("+"..string.rep("-",(#strMenuLine-2)).."+",1)
  31.   centerText(strMenuLine,2)
  32.   centerText("+"..string.rep("-",(#strMenuLine-2)).."+",3)
  33.   local id, key = os.pullEvent()
  34.   if id == "key" then
  35.    if key == 205 then
  36.     selected = selected + 1
  37.     if selected > #menuOptions then
  38.      selected = 1
  39.     end
  40.    elseif key == 203 then
  41.     selected = selected - 1
  42.     if selected < 1 then
  43.      selected = #menuOptions
  44.     end
  45.    elseif key == 28 then
  46.     return selected
  47.    end
  48.   end
  49. end
  50. end
  51. x = start()
  52. print()
  53. if x == 1 then
  54. one()
  55. end
  56. if x == 2 then
  57. two()
  58. end
  59. if x == 3 then
  60. three()
  61. end
Advertisement
Add Comment
Please, Sign In to add comment