Advertisement
grand_mind1

Selector Menu

Mar 31st, 2013
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. options={ --This begins my options table.
  2.   "option1",
  3.   "option2",
  4.   "option3",
  5. }
  6. function drawMenu() --Function where I draw the menu on the screen.
  7.   if sel == 1 then--Tries to decide what the selected option is and draws the screen depending on that
  8.     print("["..options[1].."]\n".. options[2].."\n".. options[3])
  9.   elseif sel == 2 then
  10.     print(options[1].."\n["..options[2].."]\n"..options[3])
  11.   elseif sel == 3 then
  12.     print(options[1].."\n"..options[2].."\n["..options[3].."]")
  13.   else
  14.     print("What?") --Pretty much just for  debugging purposes
  15.   end
  16. end
  17.  
  18. function clear() --Had to clear the screen a lot so I thought"Well! May as well make a function for it!"
  19.   term.clear()
  20.   term.setCursorPos(1,1)
  21. end
  22.  
  23. sel = 1--The first option is selected when the screen is first drawn
  24.  
  25. clear()--clear the screen before starting
  26. while true do
  27.   drawMenu()--draw the menu
  28.   event, key=os.pullEvent("key")--wait for a key to be pressed
  29.   if key == 200 and sel ~= 1 then--long and excessive logic(I feel it could be improved) to decide what to select next
  30.     sel = sel-1
  31.     clear()
  32.   elseif key == 200 and sel == 1 then
  33.     sel = sel
  34.     clear()
  35.   elseif key == 208 and sel ~= 3 then
  36.     sel = sel+1
  37.     clear()
  38.   elseif key == 208 and sel == 3 then
  39.     sel = sel
  40.     clear()
  41.   else
  42.     sel = sel
  43.     clear()
  44.   end
  45. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement