Command Box Help

I need help with my Command Box. I looked around how to make it run a console command when click,but no luck.

[lua]
local TestingComboBox = vgui.Create( “DComboBox”, House )
TestingComboBox:SetPos( 10, 35 )
TestingComboBox:SetSize( 100, 185 )
TestingComboBox:SetMultiple( false )
TestingComboBox:AddItem( “Abandon House” )
TestingComboBox:AddItem( “Apartment 101”)
TestingComboBox:AddItem( “Apartment 102” )
TestingComboBox:AddItem( “Apartment 103” )
TestingComboBox:AddItem( “Apartment 104” )
TestingComboBox:AddItem( “Apartment 201” )
TestingComboBox:AddItem( “Apartment 202” )
TestingComboBox:AddItem( “Apartment 203” )
TestingComboBox:AddItem( “Apartment 204” )
TestingComboBox:AddItem( “Apartment 301” )
TestingComboBox:AddItem( “Apartment 302” )
TestingComboBox:AddItem( “Apartment 303” )
TestingComboBox:AddItem( “Apartment 304” )
TestingComboBox:AddItem( “Business Suite 201” )
TestingComboBox:AddItem( “Business Suite 202” )
TestingComboBox:AddItem( “Business Suite 203” )
TestingComboBox:AddItem( “Business Suite 204” )
TestingComboBox:AddItem( “Cub Foods” )
TestingComboBox:AddItem( “Fixed Upper” )
TestingComboBox:AddItem( “Giga Computer” )

local MainMenuSheet = vgui.Create( “DPanel”,Panel) – We create a panel so we can draw shit on; if we use the frame, it comes up transparent for some reason
MainMenuSheet:SetPos( 125, 50 )
MainMenuSheet:SetSize(Panel:GetWide() - 25,Panel:GetTall() - 25 )
MainMenuSheet.Paint = function()
if TestingComboBox:GetSelectedItems() and TestingComboBox:GetSelectedItems()[1] then – make sure something is selected if not we get uber spam of errors
local OurStringThing = “Your selection is: “…TestingComboBox:GetSelectedItems()[1]:GetValue()…”!” – This was a pain in the ass to figure out; this gets the name of the option chosen
surface.SetFont( “default” )
surface.SetTextColor( 255, 255, 255, 255 )
surface.SetTextPos( 50, 50 )
surface.DrawText( OurStringThing ) – Draws the text
end
end
[/lua]

What I want t do is when i click on the place, it runs a command like “Buy house”. I am new to lua scripting, so all help is well taken…
(I have tired gmod wiki too)
Thanks

I don’t know if this some how could work

DComboBoxItem.OnMousePressed

This should go in Newbie Questions, but I believe you should use a table or maybe something like this

[lua]TestingComboBox:AddItem(“Aparment 101”, “Buy House”)

RunConsoleCommand(“v[2]”)[/lua]

I’m not sure though.

Not only does **[DComboBox.AddItem

http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?title=DComboBox.AddItem)** only take 1 argument, but that code doesn’t make sense.

I would do something like this:
[lua]
function table.Index(tab, val)
for k,v in pairs(tab) do
if(v == val) then
return k
end
end
end
TableOfCommands = {{“say”, “I chose option 1!”}, {“say”, “I chose option 2!”}}
TableOfItems = {“Herp”, “Derp”, “Durr”}
Button.DoClick = function()
local Index = table.Index(TableOfItems, TestingComboBox:GetSelectedItems()[1]:GetValue())
RunConsoleCommand(unpack(TableOfCommands[Index]))
end
[/lua]

There might be a better way, and there probably is, but it’s 3:30 AM, and I don’t feel like looking.