Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function cls()
- term.setCursorPos(1,1)
- term.clear()
- end
- --[[ Local variables ]]--
- local termWidth, termHeight = term.getSize()
- local selectedItem = 1
- local inMainMenu = true
- local inOtherMenu = false
- local reactor = false
- local reac = "Off"
- local onoff = 0
- local reacJel = "right"
- local monJel = "top"
- local monJel2 = "back"
- local monitor = true
- local mon = "On"
- local mononoff = 1
- local tempJel = "left"
- local temp = rs.getInput(tempJel)
- local temperature = ""
- --[[ Menu Methods ]]--
- function Choice1()
- onoff = math.fmod( onoff+1, 2 )
- if onoff == 0 then
- reac = "Off"
- reactor = false
- rs.setOutput(reacJel, reactor)
- elseif onoff == 1 then
- reac = "On"
- reactor = true
- rs.setOutput(reacJel, reactor)
- else
- cls()
- rs.setOutput(reacJel, false)
- print("ERROR 1: reactor: " .. reactor)
- reactor = false
- sleep(2)
- end
- end
- function Choice2()
- mononoff = math.fmod( mononoff+1, 2 )
- if mononoff == 0 then
- mon = "Off"
- monitor = false
- rs.setOutput(monJel, monitor)
- rs.setOutput(monJel2, monitor)
- elseif mononoff == 1 then
- mon = "On"
- monitor = true
- rs.setOutput(monJel, monitor)
- rs.setOutput(monJel2, monitor)
- else
- cls()
- rs.setOutput(monJel, false)
- rs.setOutput(monJel2, false)
- print("ERROR 1: monitor: " .. monitor)
- monitor = false
- sleep(2)
- end
- end
- function Option1()
- term.clear()
- term.setCursorPos(1,1)
- print("Hi")
- sleep(2)
- selectedItem = 1
- end
- function Back()
- selectedItem = 1
- inOtherMenu = false
- end
- function Exit()
- rs.setOutput(reacJel, false)
- cls()
- inMainMenu = false
- end
- --[[ Menu Definitions ]]--
- mainMenu = {
- [1] = { text = "Reactor on/off: ", handler = Choice1 },
- [2] = { text = "Monitor on/off: ", handler = Choice2 },
- [3] = { text = "Exit", handler = Exit }
- }
- otherMenu = {
- [1] = { text = "Option 1", handler = Option1 },
- [2] = { text = "Back", handler = Back }
- }
- --[[ Printing Methods ]]--
- function printMenu(menu)
- for i=1,#menu do
- if i == selectedItem then
- print(">> "..menu[i].text)
- else
- print(" "..menu[i].text)
- end
- end
- end
- --[[ Handler Methods ]]--
- function onKeyPressed( key, menu )
- if key == keys.enter then
- onItemSelected(menu)
- elseif key == keys.up then
- if selectedItem > 1 then
- selectedItem = selectedItem - 1
- end
- elseif key == keys.down then
- if selectedItem < #menu then
- selectedItem = selectedItem +1
- end
- end
- end
- function onItemSelected(menu)
- menu[selectedItem].handler()
- end
- --[[ Main Method ]]--
- function main()
- while inMainMenu do
- term.clear()
- term.setCursorPos(1,1)
- printMenu(mainMenu)
- term.setCursorPos(20,1)
- print(reac .. " " .. temperature)
- term.setCursorPos(20,2)
- print(mon)
- event, key = os.pullEvent("key")
- onKeyPressed(key, mainMenu)
- end
- end
- --[[ Main program ]]--
- rs.setOutput(monJel, monitor)
- rs.setOutput(reacJel, reactor)
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement