Advertisement
Guest User

menu

a guest
Jun 25th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.95 KB | None | 0 0
  1. term.clear()
  2. term.setCursorPos(1,1)
  3. selected = 1
  4. running = true
  5.  
  6. a = {
  7.   {"Option 1"},
  8.   {"Option 2"},
  9.   {"Option 3"}
  10. }
  11.  
  12. function printCentered(str)
  13.   local x, y = term.getCursorPos()
  14.   local maxX, maxY = term.getSize()
  15.   term.setCursorPos(maxX/2-string.len(str)/2,y)
  16.   write(str)
  17.   term.setCursorPos(1,y+1)
  18. end
  19.  
  20. function selector(array)
  21.   local event, param = os.pullEvent("key")
  22.   if event == "key" then
  23.     if param == 200 and selected > 1 then
  24.       selected = selected - 1
  25.     elseif param == 208 and selected < table.getn(array) then  
  26.       selected = selected + 1
  27.     elseif param == 28 then  
  28.       array[selected][2]()
  29.     end
  30.   end  
  31. end
  32.  
  33. function display(array)
  34.   for i = 1,table.getn(array) do
  35.     if i == selected then
  36.       printCentered("["..array[i][1].."]")
  37.     else
  38.       printCentered(array[i][1])
  39.     end
  40.   end
  41. end
  42.  
  43. while running do
  44.   term.clear()
  45.   term.setCursorPos(1,8)
  46.   display(a)
  47.   selector(a)
  48. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement