Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.pullEvent = os.pullEventRaw
- local w,h = term.getSize()
- function printCentered( y,s )
- local x = math.floor((w - string.len(s)) / 2)
- term.setCursorPos(x,y)
- term.clearLine()
- term.write( s )
- end
- local nOption = 1
- local function drawMenu()
- term.clear()
- term.setCursorPos(1,1)
- term.write("BBC V6.3")
- term.setCursorPos(1,2)
- term.setCursorPos(w-11,1)
- if nOption == 1 then
- term.write("TurtleMenu")
- elseif nOption == 2 then
- term.write("Chat")
- elseif nOption == 3 then
- term.write("Calculator")
- elseif nOption == 4 then
- term.write("Notes")
- elseif nOption == 5 then
- term.write("Games")
- elseif nOption == 6 then
- term.write("Options")
- elseif nOption == 7 then
- term.write("Reboot")
- elseif nOption == 8 then
- term.write("Shutdown")
- else
- end
- end
- --GUI
- term.clear()
- local function drawFrontend()
- printCentered( math.floor(h/2) - 3, "")
- printCentered( math.floor(h/2) - 2, "" )
- printCentered( math.floor(h/2) - 1, "")
- printCentered( math.floor(h/2) + 0, ((nOption == 1) and "[ TurtleMenu ]") or "TurtleMenu" )
- printCentered( math.floor(h/2) + 1, ((nOption == 2) and "[ Chat ]") or "Chat" )
- printCentered( math.floor(h/2) + 2, ((nOption == 3) and "[ Calculator ]") or "Calculator" )
- printCentered( math.floor(h/2) + 3, ((nOption == 4) and "[ Notes ]") or "Notes" )
- printCentered( math.floor(h/2) + 4, ((nOption == 5) and "[ Games ]") or "Games" )
- printCentered( math.floor(h/2) + 5, ((nOption == 6) and "[ Options ]") or "Options" )
- printCentered( math.floor(h/2) + 6, ((nOption == 7) and "[ Reboot ]") or "Reboot" )
- printCentered( math.floor(h/2) + 7, ((nOption == 8) and "[ Shutdown ]") or "Shutdown" )
- end
- --Display
- drawMenu()
- drawFrontend()
- while true do
- local e,p = os.pullEvent()
- if e == "key" then
- local key = p
- if key == 17 or key == 200 then
- if nOption > 1 then
- nOption = nOption - 1
- drawMenu()
- drawFrontend()
- end
- elseif key == 31 or key == 208 then
- if nOption < 4 then
- nOption = nOption + 1
- drawMenu()
- drawFrontend()
- end
- elseif key == 28 then
- --End should not be here!!
- break
- end --End should be here!!
- end
- end
- term.clear()
- --Conditions
- if nOption == 1 then
- shell.run("turtlemenu")
- elseif nOption == 2 then
- shell.run("chat")
- elseif nOption == 3 then
- shell.run("calculator")
- elseif nOption == 4 then
- shell.run("notes")
- elseif nOption == 5 then
- shell.run("games")
- elseif nOption == 6 then
- shell.run("options")
- elseif nOption == 7 then
- os.reboot()
- elseif nOption == 8 then
- os.shutdown()
- else
- shell.run("menu")
- end
RAW Paste Data
Copied