Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- State is the variable representing the current menu.
- It can be anything as long as it's a string.
- It is easier if you keep the string 'state' as short as possible.
- ]]--
- --[[
- check lights
- ]]--
- l = rs.getBundledInput("back")
- print(l)
- local state = "main"
- local doorsState = "closed"
- local lightsState = "on"
- running = true
- --[[
- Here we define a table containing the options for
- the main menu and the menu on the 'info' screen.
- ]]--
- local tMainOptions = { "[ Programs ]", "[ Info ]", "[ Quit ]" }
- local tInfoOptions = { "[ Credits ]", "[ Back ]" }
- local tProgramsList = { "[ Door Control ]", "[ Lights ]", "[ Back ]" }
- local tDoorControl = { "[ Open ]", "[ Close ]", "[ Back ]" }
- local tLightsControl = { "[ On ]", "[ Off ]", "[ Back ]" }
- --[[
- The following lines of code are function definitions for the
- draw functions of the menu.
- ]]--
- local function drawMain() -- defines the drawMain function, which obviously draws the main menu
- term.clear()
- term.setCursorPos(2,1)
- term.write("Main Menu")
- for i = 1, #tMainOptions do -- starts a for loop to print all the options in the table 'tMainOptions'
- term.setCursorPos(2,1 + (i * 2)) -- makes the cursor skip a line every time it prints an option
- term.write(tMainOptions[i]) -- prints the menu options as a 'button'
- end
- end
- local function drawPrograms() -- defines the drawPrograms function, which draws the contents of the 'game'
- term.clear()
- term.setCursorPos(2,1)
- term.write("List of available programs")
- for i = 1, #tProgramsList do
- term.setCursorPos(2,1 + (i * 2))
- term.write(tProgramsList[i])
- end
- end
- local function drawDoors() -- defines the drawDoors function, which draws the contents of the 'game'
- term.clear()
- term.setCursorPos(2,1)
- term.write("Doors: " .. doorsState)
- for i = 1, #tDoorControl do
- term.setCursorPos(2,1 + (i * 2))
- term.write(tDoorControl[i])
- end
- end
- local function drawLights() -- defines the drawLights function, which draws the contents of the 'game'
- term.clear()
- term.setCursorPos(2,1)
- term.write("Lights: " .. lightsState)
- for i = 1, #tLightsControl do
- term.setCursorPos(2,1 + (i * 2))
- term.write(tLightsControl[i])
- end
- end
- local function drawInfo() -- defines the drawInfo function, which is similar to the function 'drawMain()'
- term.clear()
- term.setCursorPos(2,1)
- term.write("Info")
- for i = 1, #tInfoOptions do
- term.setCursorPos(2,1 + (i * 2))
- term.write(tInfoOptions[i])
- end
- end
- local function drawCredits() -- defines the drawCredits function
- term.clear()
- term.setCursorPos(2,1)
- term.write("Credits")
- term.setCursorPos(2,2)
- term.write("Chris is a Nigga ")
- term.write(" NIGNOG")
- end
- --[[
- Here we start the menu's functionality
- ]]--
- while running do -- start an infinite loop
- if state == "main" then -- if the current menu is the main menu
- drawMain() -- calls the drawMain() function, which draws the main menu
- local event, button, X, Y = os.pullEvent("mouse_click") -- waits for a mouse click
- if button == 1 then -- if the user clicks with the left button (1 is left, 2 is right)
- for i = 1, #tMainOptions do -- some 'complicated' code to check where the mouse click was
- if X >= 2 and X <= #(tMainOptions[i]) + 2 and Y == 1 + (i * 2) then
- if i == 1 then
- state = "programs"
- elseif i == 2 then
- state = "info"
- elseif i == 3 then
- state = "exit"
- end
- end
- end
- end
- elseif state == "programs" then
- drawPrograms() -- draws the contents of the 'game'
- local event, button, X, Y = os.pullEvent("mouse_click") -- waits for a mouse click
- if button == 1 then
- for i = 1, #tProgramsList do
- if X >= 2 and X <= #(tProgramsList[i]) + 2 and Y == 1 + (i * 2) then
- if i == 1 then
- state = "door_control"
- elseif i == 2 then
- state = "lights"
- elseif i == 3 then
- state = "main"
- end
- end
- end
- end
- elseif state == "door_control" then
- drawDoors() -- draws the contents of the 'lights'
- local event, button, X, Y = os.pullEvent("mouse_click") -- waits for a mouse click
- if button == 1 then
- for i = 1, #tDoorControl do
- if X >= 2 and X <= #(tDoorControl[i]) + 2 and Y == 1 + (i * 2) then
- if i == 1 then
- doorsState = "open"
- elseif i == 2 then
- doorsState = "closed"
- elseif i == 3 then
- state = "programs"
- end
- end
- end
- end
- elseif state == "lights" then
- drawLights() -- draws the contents of the 'lights'
- local event, button, X, Y = os.pullEvent("mouse_click") -- waits for a mouse click
- if button == 1 then
- for i = 1, #tLightsControl do
- if X >= 2 and X <= #(tLightsControl[i]) + 2 and Y == 1 + (i * 2) then
- if i == 1 then
- lightsState = "on"
- elseif i == 2 then
- lightsState = "off"
- elseif i == 3 then
- state = "programs"
- end
- end
- end
- end
- elseif state == "info" then
- drawInfo()
- local event, button, X, Y = os.pullEvent("mouse_click") -- waits for a mouse click
- if button == 1 then
- for i = 1, #tInfoOptions do
- if X >= 2 and X <= #(tMainOptions[i]) + 2 and Y == 1 + (i * 2) then
- if i == 1 then
- state = "credits"
- elseif i == 2 then
- state = "main"
- end
- end
- end
- end
- elseif state == "credits" then
- drawCredits() -- draw the credits
- sleep(2) -- wait 2 seconds
- state = "main" -- return to the main menu
- elseif state == "exit" then
- running = false
- end
- if lightsState == "on" then
- rs.setBundledOutput("back",colors.combine(rs.getBundledOutput("back"), colors.yellow))
- elseif lightsState == "off" then
- rs.setBundledOutput("back",colors.subtract(rs.getBundledOutput("back"), colors.yellow))
- end
- if doorsState == "open" then
- rs.setBundledOutput("back",colors.combine(rs.getBundledOutput("back"), colors.blue))
- elseif doorsState == "closed" then
- rs.setBundledOutput("back",colors.subtract(rs.getBundledOutput("back"), colors.blue))
- end
- end
- -- Clean up
- term.clear()
- term.setCursorPos(1,1)
Advertisement
Add Comment
Please, Sign In to add comment