Guest User

Basic menu for CC by Big SHiny Toys

a guest
May 5th, 2012
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.92 KB | None | 0 0
  1. --[[
  2.             Basic Menu
  3.             by
  4.             Big Shiny Toys
  5.            
  6. ]]--
  7. local function menu()
  8.  
  9.     local sel = 1
  10.     local list = {"Item one","Item two","item three"} -- add as many items as you want
  11.     local offX,offY = 1,1 -- change this to what ever off set you want
  12.     local curX,curY = term.getCursorPos()
  13.  
  14.     while true do
  15.         if sel > #list then sel = #list end
  16.         if sel < 1 then sel = 1 end
  17.         for i = 1,#list do
  18.             term.setCursorPos(offX,offY+i-1)
  19.             if sel == i then
  20.                 print("["..list[i].."]")
  21.             else
  22.                 print(" "..list[i].." ")
  23.             end
  24.         end
  25.         while true do
  26.             local e,e1,e2,e3,e4,e5 = os.pullEvent()
  27.             if e == "key" then
  28.                 if e1 == 200 then -- up key
  29.                     sel = sel-1
  30.                     break
  31.                 end
  32.                 if e1 == 208 then -- down key
  33.                     sel = sel+1
  34.                     break
  35.                 end
  36.                 if e1 == 28 then
  37.                     term.setCursorPos(curX,curY)
  38.                     return sel
  39.                 end
  40.             end
  41.         end
  42.     end
  43. end
  44. term.clear() -- clears all test from screen
  45.  
  46. print(menu())
Advertisement
Add Comment
Please, Sign In to add comment