Lua list and select

I’m very new at lua, I decided to learn it so I could make a menu. Is there a way to make a list of things I could select from (not buttons), then I would press a button and it would run a different command based on what item was selected.

If you saw my previous post, you would know that I was trying to copy code from another addon to do this, but I decided not to do it.

For an example of what I want this to look like, look at this: http://steamcommunity.com/sharedfiles/filedetails/?id=119928922

How would I make the combo box change the command the button will run

You could have a table with the commands corresponding to the item in the DComboBox



local commands = {
	"kill",
	"kill",
	"kill"
}


Value, in the OnSelect function would be the index of the command



DComboBox.OnSelect = function( panel, index, value )
	RunConsoleCommand(commands[value])
end


But that will make it run a command when I press on the combo box item, is there a way I could set a variable for what the button does and the combo box changes the variable? Sorry if that sounds dumb, my knowledge is coming from what I know of Java.

I’m thinking that I could do this


local DButton = vgui.Create( "DButton", DPanel )
	DButton:SetSize( 160, 40 )
	DButton:SetText( "test" )
	DButton:SetPos( 20, 30 )
	DButton:DoClick = function()
		RunConsoleCommand(commands[value])
	end
	

But I don’t think it would connect it to the combo box.



local selected
DComboBox.OnSelect = function( panel, index, value )
	selected = value
end

RunConsoleCommand(commands[selected])