Posted 19 February 2015 - 09:24 PM
Hi, thanks for reading this to begin with, I am here today to give you a bit of code which should help if you want to create a programme which has multiple menus and multiple selections
here is the code and thank you for taking the time to read it
here is the code and thank you for taking the time to read it
-- Menu Program
-- Coded and Produced by Paullie
-- www.youtube.com/user/AllGamesWide
--Menu Selection
local tSel = {
"Test 1",
"Test 2",
"Test 3"
}
-- Starting Co-Ords for the Table
local startX = 2
local startY = 2
-- Menu to create/print
-- and everything else
local function startMenu(tMenu, sTitle)
local function printMenu(tMenu, sTitle, nSelected)
for index, text in pairs(tMenu) do
term.setCursorPos(startX, startY + index - 1)
write( (nSelected == index and '[' or ' ') .. text .. (nSelected == index and ']' or ' ') )
end --For Index
end --Function printMenu
--Setting Default Selection for Menu
local selection = 1
--Creating the loop till enter is entered
while true do
printMenu(tMenu, sTitle, selection)
event, button = os.pullEvent("key")
if button == key.up then
--Up button pressed
selection = selection - 1
elseif button == key.down then
--Down button pressed
selection = selection + 1
elseif button == key.enter then
--Enter button pressed
--To return text and number of option entered
return tMenu[selection], selection
end --If function
--this adds the automated increase for the table
selection = selection < 1 and #tMenu or selection > #tMenu and 1 or selection
end --printMenu function
end --while function
--Clearing the terminal
term.clear()
--Starting the whole process
sOptions, nNumb = startMenu(tSel)
term.clear()
term.setCursorPos(1,1)
--Part of the code which controls what happens upon enter and which option
if nNumb == 1 then
--shell.run("programme name")
elseif nNumb == 2 then
elseif nNumb == 3 then
end --nNumb 3
end --nNumb 2
end --nNumb 1
Edited on 19 February 2015 - 08:25 PM