23 posts
Posted 16 February 2013 - 06:56 AM
I have searched the internet and I have been unable to find a program that will create a vertical gui menu. I would like for it automatically center on the screen and return the selection made.
Example Vertical Menu (Not Centered):
Title
[Selection 1]
Selection 2
selection 3
404 posts
Location
St. Petersburg
Posted 16 February 2013 - 07:13 AM
come here to ask for help, not for programs
all of us are happy to help you debug the program and answer questions about it, but you still should write it
386 posts
Location
France
Posted 16 February 2013 - 07:16 AM
I think we should add a programs requests sections on the forum
23 posts
Posted 16 February 2013 - 07:21 AM
I found this program
http://pastebin.com/cKW626VM and it works well, but I need one that would automatically center on the screen and return the selection.
2088 posts
Location
South Africa
Posted 16 February 2013 - 07:23 AM
Easiest way is using tables… take this for example (read comments)
If you need me to explain more, ask away :)/>
-- Create a table with the selections
local tSelections = {
"Selection 1",
"Selection 2",
"Selection 3"
}
-- Starting co-ords for table
local startYPos = 3
local startXPos = 5
-- Menu to create/print ... do everything really :P/>
local function startMenu( tMenu, sTitle )
-- This function just prints the menu
local function printMenu( tMenu, sTitle, nSelected )
for index, text in pairs( tMenu ) do
term.setCursorPos( startXPos, startYPos + index - 1 )
write( (nSelected == index and '[' or ' ') .. text .. (nSelected == index and ']' or ' ') )
end
end
-- Set default selection to the first one
local selection = 1
-- Inifinite loop until enter is clicked
while true do
printMenu( tMenu, sTitle, selection )
event, but = os.pullEvent("key")
if but == keys.up then
-- Up
selection = selection - 1
elseif but == keys.down then
-- Down
selection = selection + 1
elseif but == keys.enter then
-- Enter
return tMenu[selection], selection -- returns the text AND the number
end
-- Advanced way to make the selection 1 if you have gone past the amount of items in the menu,
-- or make it the amount of items in the menu/table if you have gone past above the first selection
selection = selection < 1 and #tMenu or selection > #tMenu and 1 or selection
end
end
term.clear()
sOption, nNumb = startMenu( tSelections ) -- start the function ... 'sOption' and 'nNumb'
term.clear()
term.setCursorPos(1, 1)
print(sOption)
print(nNumb)
-- Two ways of doing it
if sOption == "Selection 1" then
elseif nNumb == 1 then
end
23 posts
Posted 16 February 2013 - 07:32 AM
Easiest way is using tables… take this for example (read comments)
If you need me to explain more, ask away :)/>
-- Create a table with the selections
local tSelections = {
"Selection 1",
"Selection 2",
"Selection 3"
}
-- Starting co-ords for table
local startYPos = 3
local startXPos = 5
-- Menu to create/print ... do everything really :P/>/>
local function startMenu( tMenu, sTitle )
-- This function just prints the menu
local function printMenu( tMenu, sTitle, nSelected )
for index, text in pairs( tMenu ) do
term.setCursorPos( startXPos, startYPos + index - 1 )
write( (nSelected == index and '[' or ' ') .. text .. (nSelected == index and ']' or ' ') )
end
end
-- Set default selection to the first one
local selection = 1
-- Inifinite loop until enter is clicked
while true do
printMenu( tMenu, sTitle, selection )
event, but = os.pullEvent("key")
if but == keys.up then
-- Up
selection = selection - 1
elseif but == keys.down then
-- Down
selection = selection + 1
elseif but == keys.enter then
-- Enter
return tMenu[selection], selection -- returns the text AND the number
end
-- Advanced way to make the selection 1 if you have gone past the amount of items in the menu,
-- or make it the amount of items in the menu/table if you have gone past above the first selection
selection = selection < 1 and #tMenu or selection > #tMenu and 1 or selection
end
end
term.clear()
sOption, nNumb = startMenu( tSelections ) -- start the function ... 'sOption' and 'nNumb'
term.clear()
term.setCursorPos(1, 1)
print(sOption)
print(nNumb)
-- Two ways of doing it
if sOption == "Selection 1" then
elseif nNumb == 1 then
end
Thx this will work just fine.
404 posts
Location
St. Petersburg
Posted 16 February 2013 - 09:05 PM
I think we should add a programs requests sections on the forum
this is a great idea :)/> let them get it out of their systems in that forum instead of plaguing this one