So.. I have a DComboBox and I want it to basically, when you click on something it runs a label.
[lua]
local DrugBox = vgui.Create( "DComboBox", drugs )
DrugBox:SetPos( 10, 35 )
DrugBox:SetSize( 175, 160 )
local heroin1 = DrugBox:AddItem( "heroin" )
DrugBox:AddItem( "weed" )
DrugBox:AddItem( "beer" )
DrugBox:AddItem( "cigarretes" )
DrugBox:AddItem( "cocaine" )
DrugBox:AddItem( "shrooms" )
DrugBox:AddItem( "aspirin" )
DrugBox:AddItem( "lsd" )
heroin1:SetSelected(true)
currents = sql.QueryValue("SELECT status FROM Drugs WHERE item = '"..DrugBox:GetSelectedItems()[1]:GetValue().."'")
local Legal = vgui.Create("DLabel", drugs )
Legal:SetText("It is currently "..currents.." to have "..DrugBox:GetSelectedItems()[1]:GetValue()..".")
Legal:SizeToContents()
Legal:SetPos( 350, 250 )
[/lua]
Above is my snip of code.
Error: \gamemode\cl_vgui.lua:737: attempt to index field '?' (a nil value)
I think the error is being caused because nothing is selected but I added the heroin1:SetSelected(true) to select one. Anyways thanx for any help.
That code looks fine to me, try adding an if function around lines 15-19 to check whether an item is selected or not first.
if DrugBox:GetSelectedItems and DrugBox:GetSelectedItems[1] then
[QUOTE=Drakehawke;23704901]That code looks fine to me, try adding an if function around lines 15-19 to check whether an item is selected or not first.
if DrugBox:GetSelectedItems and DrugBox:GetSelectedItems[1] then[/QUOTE]
Please fully read my post as, I have already done that.
[QUOTE=zzaacckk;23705331]Please fully read my post as, I have already done that.[/QUOTE]
I know you said you added that, but this is to check that's working.
Oh, it still dosent work.
Sorry, you need to Log In to post a reply to this thread.