• Lua list and select
    5 replies, posted
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: [url]http://steamcommunity.com/sharedfiles/filedetails/?id=119928922[/url]
[url]http://wiki.garrysmod.com/page/Category:DComboBox[/url]
[QUOTE=Exho;46443948][url]http://wiki.garrysmod.com/page/Category:DComboBox[/url][/QUOTE]How would I make the combo box change the command the button will run
[QUOTE=Gleir;46444254]How would I make the combo box change the command the button will run[/QUOTE] You could have a table with the commands corresponding to the item in the DComboBox [CODE] local commands = { "kill", "kill", "kill" } [/CODE] Value, in the OnSelect function would be the index of the command [CODE] DComboBox.OnSelect = function( panel, index, value ) RunConsoleCommand(commands[value]) end [/CODE]
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 [CODE]local DButton = vgui.Create( "DButton", DPanel ) DButton:SetSize( 160, 40 ) DButton:SetText( "test" ) DButton:SetPos( 20, 30 ) DButton:DoClick = function() RunConsoleCommand(commands[value]) end [/CODE] But I don't think it would connect it to the combo box.
[CODE] local selected DComboBox.OnSelect = function( panel, index, value ) selected = value end RunConsoleCommand(commands[selected]) [/CODE]
Sorry, you need to Log In to post a reply to this thread.