Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- term.clear()
- term.setCursorPos(1,1)
- selected = 1
- running = true
- a = {
- {"Option 1"},
- {"Option 2"},
- {"Option 3"}
- }
- function printCentered(str)
- local x, y = term.getCursorPos()
- local maxX, maxY = term.getSize()
- term.setCursorPos(maxX/2-string.len(str)/2,y)
- write(str)
- term.setCursorPos(1,y+1)
- end
- function selector(array)
- local event, param = os.pullEvent("key")
- if event == "key" then
- if param == 200 and selected > 1 then
- selected = selected - 1
- elseif param == 208 and selected < table.getn(array) then
- selected = selected + 1
- elseif param == 28 then
- array[selected][2]()
- end
- end
- end
- function display(array)
- for i = 1,table.getn(array) do
- if i == selected then
- printCentered("["..array[i][1].."]")
- else
- printCentered(array[i][1])
- end
- end
- end
- while running do
- term.clear()
- term.setCursorPos(1,8)
- display(a)
- selector(a)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement