Hello
[Goodbye]
Hi
"[]" representing what is selecting. I know you can detect what key you press with events but I don't know how I would change what is selected. If someone could explain this to me that would be great!
Help is appreciated!
Thanks!
Posted 24 February 2013 - 12:53 PM
Posted 24 February 2013 - 01:32 PM
Posted 24 February 2013 - 03:08 PM
Posted 24 February 2013 - 03:56 PM
....
function RunServerMenu()
dark.splash(1.5, "Powered by DarkGui")
state = "main"
Page = 0
while true do
term.clear()
term.setCursorPos(1,1)
if Co[state].draw then
Co[state].draw()
_, key = os.pullEvent("char")
key = tonumber(key)
if Co[Co[state].options[key]] then
state = Co[state].options[key]
else
print("\nOption doesn't exist!")
sleep(2)
end
else
Co[state].Run()
state = Co[state].Parent
end
end
end
....
Posted 24 February 2013 - 10:52 PM
local tab = {
"Hi",
"Goodbye",
"Hello",
"Exit"
}
local sX, sY = term.getSize()
local function menu( _table, startX, startY )
local function getLongest( _table )
local longest = 0
for index, text in pairs( _table ) do
longest = #text > longest and #text or longest
end
return longest + 2
end
local function printMenu( _table, long, sel )
for index, text in pairs( _table ) do
term.setCursorPos( startX, startY + index - 1 )
write( ( index == sel and '[ ' or ' ' ) .. text .. string.rep(' ', long - #text) .. ( index == sel and ']' or ' ' ) )
end
end
local longest = getLongest( _table )
local sel = 1
while true do
printMenu( _table, longest, sel )
local _, key = os.pullEvent( "key" )
if key == keys.up then
sel = sel - 1
elseif key == keys.down then
sel = sel + 1
elseif key == keys.enter then
return _table[sel], sel
end
sel = sel < 1 and #_table or sel > #_table and 1 or sel
end
end
term.clear()
while true do
sOption, sNumb = menu( tab, sX/2-7, sY/2-(#tab/2) )
term.clear() term.setCursorPos( 1, 1 )
if sOption == "Hi" then
print( "Hello there! :D/>" )
elseif sOption == "Goodbye" then
print( "Why are you going? :(/>" )
elseif sOption == "Hello" then
print( "Oh hello again :>" )
elseif sOption == "Exit" then
print( "Cheers :<" )
break
end
sleep(2)
term.clear() term.setCursorPos( 1, 1 )
end
0 members, 1 guests, 0 anonymous users