Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Int--
- local w,h = term.getSize()
- local running = true
- local selectedItem = 1
- --Menu Int--
- local MainMenu = {
- [1] = {text = "Programs", handler = function() selectedMenu = "Programs" end},
- [2] = {text = "Control Options", handler = function() selectedMenu = "Control" end},
- [3] = {text = "Redstone Options", handler = function() selectedMenu = "Redstone" end},
- [4] = {text = "Exit", handler = function() running = false end}
- }
- --Functions--
- function centerPrint(string,ypos)
- term.setCursorPos(w/2-#string/2,ypos)
- write(string)
- end
- function PrintMenu(menu)
- for i=1,#menu do
- if i == selectedItem then
- centerPrint("[ "..menu[i].text.." ]",i+5)
- else
- centerPrint(" "..menu[i].text.." ",i+5)
- end
- end
- end
- function Input(key, menu)
- if key == keys.enter then
- menu[selectedItem].handler()
- elseif key == keys.down and selectedItem < #menu then
- selectedItem = selectedItem + 1
- elseif key == keys.up and selectedItem > 1 then
- selectedItem = selectedItem - 1
- end
- end
- --Main Function--
- local selectedMenu = MainMenu
- term.clear()
- term.setCursorPos(1,1)
- while running do
- PrintMenu(selectedMenu)
- local event, key = os.pullEvent("key")
- Input(key, selectedMenu)
- end
- term.clear()
- term.setCursorPos(1,1)
Advertisement
Add Comment
Please, Sign In to add comment