604 posts
Location
Spring Hill, Fl
Posted 24 December 2012 - 08:39 AM
Alright,so I am having huge projects,and it seams like im spamming or somthing,but im trying not to.So,my question is how do I put a text and using the arrow keys,make these () go around it and if you click enter,it will do something.So example:
MENU:
(Start) Reboot Exit
Something like that.I do also proboly want to know how to make it when you click enter,it will do something.
Any answers?Thanks if you do :)/> !Again.
2088 posts
Location
South Africa
Posted 24 December 2012 - 08:58 AM
Here's a nice and simple menu:
t_menuOptions = {"Start", "Reboot", "Exit"}
function menu(menuOptions)
local selected = 1
local offX,offY = term.getCursorPos()
local curX,curY = term.getCursorPos()
while true do
if selected > #menuOptions then selected = 1 end
if selected < 1 then selected = #menuOptions end
for i = 1, #menuOptions do
if selected == i then
write("("..menuOptions[i]..")")
else
write(" "..menuOptions[i].." ")
end
end
while true do
local e,e1 = os.pullEvent("key")
-- Left
if e1 == 203 then
selected = selected - 1
term.setCursorPos(curX,curY)
break
end
-- Right
if e1 == 205 then
selected = selected+1
term.setCursorPos(curX,curY)
break
end
-- Right
if e1 == 28 then
term.setCursorPos(curX,curY)
return menuOptions[selected]
end
end
end
end
option = menu(t_menuOptions)
if option == t_menuOptions[1] then
-- Start
elseif option == t_menuOptions[2] then
-- Reboot
os.reboot()
elseif option == t_menuOptions[3] then
-- Exit
end
604 posts
Location
Spring Hill, Fl
Posted 24 December 2012 - 09:02 AM
God,I really need to learn how to understand this!But thanks though!
604 posts
Location
Spring Hill, Fl
Posted 09 January 2013 - 12:53 PM
Ok,so I kinda was expirimenting with this,and now when ever I press <,it will change the menu options around :P/>!
2005 posts
Posted 09 January 2013 - 06:33 PM
You messed with the for loop didn't you?
Well, if you need help fixing it, you should probably post the revised code.