Posted 20 January 2013 - 05:51 AM
Arrow key menus are hard to make.
Here is how to make one (easy-medium difficulty)
Example 1
This will make a simple yes/no menu. Feel free to modify the print()s to what you like.
Will be making a more advanced tutorial soon!
Here is how to make one (easy-medium difficulty)
Example 1
function myMenu() -- Define menu
opt = 1 -- Set the selected option to 1
while true do -- Begin loop
term.clear()
term.setCursorPos(1,1)
if opt == 1 then -- If yes selected?
print("YES no")
else -- Its not
print("yes NO")
end
e, a, b = os.pullEvent("key") -- Get key
if a == 203 and opt > 0 then -- If key is left arrow and OPT is larger than 0?
opt = 1 -- Set option to 1
elseif a == 205 and opt < 2 then -- If key is right arrow and OPT is smaller than 2?
opt = 2 -- Set option to 2
elseif a == keys.enter then -- RETURN hit?
break -- Break out of loop
end
return opt -- Return selected
end
yn = myMenu() -- Call myMenu and save returned param to yn
if yn == 1 then -- If yes selected?
print("YES!")
else -- Not selected?
print("NO!")
end
This will make a simple yes/no menu. Feel free to modify the print()s to what you like.
Will be making a more advanced tutorial soon!