Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local list = { --This contains the numbers and colors. You can extend this to as long as you'd like - it's not hardcoded anywhere else
- [1] = colors.blue,
- [2] = colors.yellow,
- [3] = colors.white,
- [4] = colors.green,
- [5] = colors.red
- }
- local function drawList(selected, offX, offY) --This function will draw the list with the selected item at the given offsets
- for i=1,#list do
- term.setCursorPos(offX, offY)
- term.setTextColor(list[i])
- if i==selected then
- term.write("["..i.."]")
- else
- term.write(" "..i.." ")
- end
- offY=offY+1
- end
- end
- local function run() --This just captures key presses and adds or subtracts from the selected variable depending on the key event. If the user presses enter, it returns true
- while true do
- local startX, startY = 3,3
- local selected = 1
- while true do
- drawList(selected, startX, startY)
- local e = {os.pullEvent()}
- if e[1] == "key" then
- if e[2] == keys.up then
- selected = selected>1 and selected - 1 or selected
- elseif e[2] == keys.down then
- selected = selected<#list and selected+1 or selected
- elseif e[2] == keys.enter then
- return selected
- end
- end
- end
- end
- end
- while true do --The main loop.
- local result = run()
- --Now you've got the result in number format. I'm not sure what you were trying to do with the book function, but I can imagine that you'll be able
- --to use this now. If you need the actual color value instead of the number, you can just use list[result] and it will give you the color.
- end
Advertisement
Add Comment
Please, Sign In to add comment