Posted 13 June 2012 - 11:42 PM
Hey all
I'm not a programmer but with the help of this board and some examples I came up with this Menu it works and is easy to edit to suite your needs. It may look confusing but once you look it over you will see its very simple to understand and edit
I'm not a programmer but with the help of this board and some examples I came up with this Menu it works and is easy to edit to suite your needs. It may look confusing but once you look it over you will see its very simple to understand and edit
--[[
This is a blank menu template as is it has 5 options and a exit
options can be added or removed to suite the user.
I would like to thank the users of this board whos know how helped in making this menu
--]]
function cls() -- function to clear the screen and set the cursor position
term.clear()
term.setCursorPos( 1, 1 )
end
function WTS() -- a function to print some stuff to the screen
for i = 1,10 do
term.setCursorPos( 18, i )
print("This is a Test")
sleep(.2)
end
end
function menu(...) -- Menu function
choice = {...}
keypress = 1
positionX,positionY = 1,1 -- sets the position of the menu on the screen
while true do
if keypress > #choice then -- this while true loop causes the selection to go
keypress = 1 -- from the first to the last selection
end -- the last selection to the first
if keypress < 1 then -- looping it so to speak
keypress = #choice
end
for i = 1 , #choice do -- this for loop moves the selection bracket
term.setCursorPos(positionX , positionY + i - 1) -- with the keypresses [highlighting] the options
if keypress == i then
print("["..choice[i].."]")
else
print(" "..choice[i].." ")
end
end
while true do -- this While true loop deals with the users choices
local event,param1 = os.pullEvent()
if event == "key" then
if param1 == 200 then -- if the up key is pressed
keypress = keypress - 1
break
end
if param1 == 208 then -- if the down key is pressed
keypress = keypress + 1
break
end
if param1 == 28 then -- if the enter key is pressed
if keypress == 1 then -- the next 5 lines are excuted you can call a function or functions
cls() -- cls() is just a function that clears the screen
WTS() -- wts() is just a function that just prints some stuff to the screen
sleep(1) -- i like things to step
shell.run("menublank") -- reloads the menublank program
end
if keypress == 2 then -- the next 5 lines are excuted when the
cls() -- enter key is pressed over a menu option 2
print("Selection " , keypress)
sleep(1)
shell.run("menublank")
end
if keypress == 3 then -- the next 5 lines are excuted when the
cls() -- enter key is pressed over a menu option 3
print("Selection " , keypress)
sleep(1)
shell.run("menublank")
end
if keypress == 4 then -- the next 5 lines are excuted when the
cls() -- enter key is pressed over a menu option 4
print("Selection " , keypress)
sleep(1)
shell.run("menublank")
end
if keypress == 5 then -- the next 5 lines are excuted when the
cls() -- enter key is pressed over a menu option 5
print("Selection " , keypress)
sleep(1)
shell.run("menublank")
end
if keypress == 6 then -- the next 3 lines are excuted when the
cls() -- enter key is pressed over a menu option 6
return -- in this case pressing the enter key exits
end -- the menu and returns to the prompt
end
end
end
end
end
cls()
print("Main Menu")
print(menu( "Selection 1", -- you can add as many options as you like
"Selection 2", -- and name them what you want
"Selection 3",
"Selection 4",
"Selection 5",
"Exit Menu"))