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