Advertisement
Jazza

Untitled

Oct 27th, 2012
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.83 KB | None | 0 0
  1. --menu API V1.0
  2. --Variables
  3. local menuSelect = 3
  4. local menuRunning = true
  5. termW, termH = term.getSize()
  6.  
  7. --Functions
  8. function printcenter(str,yLine)
  9.     term.setCursorPos(termW/2-#str/2,yLine)
  10.     print(str)
  11. end
  12.  
  13. function printMenu(...)
  14.     menuOps = {...}
  15.         while menuRunning do
  16.             term.clear()
  17.             term.setCursorPos(1,1)
  18.             for i = 2,#menuOps,1 do
  19.                 if i == menuSelect then
  20.                     term.setTextColor(tonumber(menuOps[1]))
  21.                     printcenter(menuOps[i],i+1)
  22.                 else
  23.                     term.setTextColor(1)
  24.                     printcenter(menuOps[i],i+1)
  25.                 end
  26.             end
  27.                 event, key = os.pullEvent("key")
  28.                 if  key == 200 and menuSelect > 3 then
  29.                     menuSelect = menuSelect - 1
  30.                 elseif key == 208 and menuSelect < #menuOps then
  31.                     menuSelect = menuSelect + 1
  32.                 elseif key == 28 then
  33.                     local menuRunning = false
  34.                 end
  35.         end
  36. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement