darearkin

Untitled

Apr 1st, 2013
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. local function menu(...) -- ver 0.1
  2. local sel = 1
  3. local list = {...}
  4. local offX,offY = term.getCursorPos()
  5. local curX,curY = term.getCursorPos()
  6. while true do
  7. if sel > #list then sel = 1 end
  8. if sel < 1 then sel = #list end
  9. for i = 1,#list do
  10. term.setCursorPos(offX,offY+i-1)
  11. if sel == i then
  12. print("["..list[i].."]") -- very customisible example print(">"..list[i])
  13. else
  14. print(" "..list[i].." ") -- very customisible
  15. end
  16. end
  17. while true do
  18. local e,e1,e2,e3,e4,e5 = os.pullEvent()
  19. if e == "key" then
  20. if e1 == 200 then -- up key
  21. sel = sel-1
  22. break
  23. end
  24. if e1 == 208 then -- down key
  25. sel = sel+1
  26. break
  27. end
  28. if e1 == 28 then
  29. term.setCursorPos(curX,curY)
  30. return list[sel],sel
  31. end
  32. end
  33. end
  34. end
  35. end
  36. -- Example Usage
  37. print("Please select Option")
  38. local selection = menu("Redstone","Hardware","WiFi","Event Monitor","Turtle Driver","Infomation/Help","Exit")
  39. if selection == "Redstone" then
  40. RedstoneControl()
  41. elseif selection == "Hardware" then
  42. Hardware()
  43. elseif selection == "WiFi" then
  44. wifi()
  45. elseif selection == "Event Monitor" then
  46. EventMonitor()
  47. elseif selection == "Turtle Driver" then
  48. TurtleDriver()
  49. elseif selection == "Infomation/Help" then
  50. help()
  51. elseif selection == "Exit" then
  52. bRunning = false
  53. end
Add Comment
Please, Sign In to add comment