Advertisement
Guest User

Menu by 1Ridav

a guest
Jun 3rd, 2013
954
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.21 KB | None | 0 0
  1.  
  2. menu-----------------------------------------------------------------------------
  3.  
  4. local function mprint(array, this, s1, s2, x, y)
  5.    for i = 1, #array do
  6.       term.setCursorPos(x, y)
  7.       --Check if option selected
  8.       if i == this then
  9.       --Option selected  
  10.          write(s1)
  11.       else
  12.       --Option NOT selected
  13.          write(s2)
  14.       end
  15.       --Print the string
  16.       print(array[i])
  17.       y = y + 1
  18.    end
  19. end
  20.  
  21. function CreateMenu(array, state1, state2, pos_x, pos_y)
  22.    local select = 1
  23.    local x, y = term.getCursorPos()
  24.    
  25.    while true do
  26.       term.setCursorPos(x, y)
  27.       mprint(array, select, state1, state2, pos_x, pos_y)
  28.       event, key = os.pullEvent("key")
  29.       --Enter
  30.       if key == 28 then
  31.          return select
  32.       end
  33.      
  34.       if #array > 1 then
  35.          --Arrow UP or W key
  36.          if key == 200 or key == 17 then
  37.                 select = select - 1
  38.            
  39.             if select < 1 then
  40.                select = #array
  41.             end
  42.          --Arrow Down or S key
  43.          elseif key == 208 or key == 31 then
  44.                 select = select + 1    
  45.                      if select > #array then select = 1 end
  46.           end
  47.       end  
  48.    end
  49. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement