Well, it's basically a while true do with an os.pullEvent() (waiting for the key event) until enter is pressed.
Something like this? If you need me to explain anything, ask away :)/>/>/>
screenX, screenY = term.getSize()
t = {
colSel = colours.yellow,
colNotSel = colours.lime,
difficulties = {
{ text = "Easy", diffLevel = 1, diffSpeed = 1 },
{ text = "Medium", diffLevel = 2, diffSpeed = 0.5 },
{ text = "Hard", diffLevel = 3, diffSpeed = 0.1 }
}
}
function getDifficulty()
local sel = 1 -- define which option is selected by default
while true do
for i = 1, #t.difficulties do
term.setCursorPos(math.floor((screenX-#t.difficulties[i].text)/2), math.floor(screenY/2) - 1 + i)
term.setTextColour(i == sel and t.colSel or t.colNotSel)
write(t.difficulties[i].text)
end
_, key = os.pullEvent("key")
if key == keys.down and sel < #t.difficulties then
sel = sel + 1
elseif key == keys.up and sel > 1 then
sel = sel - 1
elseif key == keys.enter then
return t.difficulties[sel].text, t.difficulties[sel].diffLevel, t.difficulties[sel].diffSpeed
end
end
end
term.clear()
difficulty, level, speed = getDifficulty()
term.clear()
term.setCursorPos(1, 1)
term.setTextColour(colours.yellow)
print( "You chose the difficulty '" .. difficulty .. "' which has the difficulty level of " .. level .. " and speed of " .. speed .. ".\n\nGoodluck!\n" )
term.setTextColour(colours.white)