Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local getSelected = 1
- local menuOptions = {"Testing", "Menu", "Options"} --The actual menu options
- local controls = {"w", "s", "f"} --Controls (up, down, select)
- local width, height = term.getSize()
- local function drawMenu()
- for i = 1, #menuOptions do
- term.setCursorPos(((width / 2) - (#menuOptions[i] / 2)), ((height / 2) - (#menuOptions / 2) + (i - 1))) --Some overcomplicated maths for the centering
- print(menuOptions[i])
- if i == getSelected then --If the option number is selected, change the colour
- term.setTextColor(colours.red)
- else
- term.setTextColor(colours.white)
- end
- end
- end
- function monitorKeys()
- while true do
- event, char = os.pullEvent("char")
- for i = 1, 3 do
- if char == controls[i] then
- if char == controls[1] then
- getSelected = getSelected - 1 --Decreases the cursor
- end
- if char == controls[2] then
- getSelected = getSelected + 1 --Increases the cursor
- end
- if char == controls[3] then
- print(menuOptions[getSelected]) --Prints the selected option
- end
- if getSelected == 0 then
- getSelected = #menuOptions
- end
- if getSelected == #menuOptions then
- getSelected = 1
- end
- drawMenu()
- end
- end
- end
- end
- term.clear()
- drawMenu()
- monitorKeys()
Advertisement
Add Comment
Please, Sign In to add comment