Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Gui using tables by PaymentOption --
- nSelect = 1
- sMenuState = "MainMenu" -- This variable helps keep track of what menu you're on.
- tMainMenu = { [1] = { label = "Option1", associatedFunction = Option1Func }, -- Format: { label = string, associatedFunction = function }
- [2] = { label = "Option2", associatedFunction = Option2Func }}; -- The label is to be displayed, and the
- -- Associated Function is what is executed upon pushing the button.
- -- Tab markers in notepad++, you don't understand...
- function clear() term.clear(); term.setCursorPos( 1, 1 ) end
- function printScreen( tMenu )
- for i=1, #tMenu do
- if nSelect == i then print( "[ " .. tMenu[i].label .. " ]" )
- else print( " " .. tMenu[i].label .. " " ) end
- end
- end
- function Option1Func()
- term.setCursorPos( 1, 1 ); term.write( "OPTION 1 PRESSED" ); sleep( 2 )
- end
- function Option2Func()
- term.setCursorPos( 1, 2 ); term.write( "OPTION 2 PRESSED" ); sleep( 2 )
- end
- while true do
- clear()
- printScreen( tMainMenu )
- event, key = os.pullEvent( "key" )
- if sMenuState == "MainMenu" then
- if key == 200 and nSelect > 1 then nSelect = nSelect-1
- elseif key == 208 and nSelect < #tMainMenu then nSelect = nSelect+1
- elseif key == 28 then tMainMenu[nSelect].associatedFunction()
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement