How do I close a derma window automatically once a player selects something?

I’ve got teams and classes set up, but I want the two windows to close once the player selects an option automatically.

Probably ridiculously easy?

[lua]
function set_team()

frame = vgui.Create( “TFrame” )
frame:SetSize( 260, 215 )
frame:SetTitle( “” )
frame:SetVisible( true )
frame:ShowCloseButton( true )
frame:MakePopup()

team_1 = vgui.Create( “DButton”, frame )
team_1:SetPos( 30, 30 )
team_1:SetSize( 100, 50 )
team_1:SetText( “Combine!” )
team_1.DoClick = function() frame:Close() --Here it is :stuck_out_tongue:
RunConsoleCommand( “team_1” )
end
[/lua]

Hope this help

Perfect, thanks very much.

[editline]04:55PM[/editline]

Works fine for the class window I have, but doesnt work at all for the team select, comes up with this error:

Test3/gamemode/cl_init.lua:18: attempt to call method ‘Close’ (a nil value)

Probably because TFrame isn’t a valid type of derma object unless you create it.

Replace TFrame with DFrame.

Sorry guys not working, the base code for the team select and class select is identical, yet it doesn’t work for the team select.

Heres the code for the team select if it helps, I’ve not included the above addition as its not working for this one.

function set_team()

frame = vgui.Create( “DFrame” )
frame:SetPos( 100, ScrH() / 2 )
frame:SetSize( 200, 210 )
frame:SetTitle( “Change Team” )
frame:SetVisible( true )
frame:SetDraggable( false )
frame:ShowCloseButton( true )
frame:MakePopup()

team_1 = vgui.Create( “DButton”, frame )
team_1:SetPos( 30, 30 )
team_1:SetSize( 100, 50 )
team_1:SetText( “Combine” )
team_1.DoClick = function()
RunConsoleCommand( “team_1” )

end

team_2 = vgui.Create( “DButton”, frame )
team_2:SetPos( 30, 85 )
team_2:SetSize( 100, 50 )
team_2:SetText( “Rebels” )
team_2.DoClick = function()
RunConsoleCommand( “team_2” )

end

end
concommand.Add( “team_menu”, set_team )

[Lua]
function set_team()

frame = vgui.Create( “DFrame” )
frame:SetPos( 100, ScrH() / 2 )
frame:SetSize( 260, 215 )
frame:SetTitle( “Change Team” )
frame:SetVisible( true )
frame:ShowCloseButton( true )
frame:MakePopup()

team_1 = vgui.Create( “DButton”, frame )
team_1:SetPos( 30, 30 )
team_1:SetSize( 100, 50 )
team_1:SetText( “Combine!” )
team_1.DoClick = function() frame:Close()
RunConsoleCommand( “team_1” )
end

team_2 = vgui.Create( “DButton”, frame )
team_2:SetPos( 30, 100 )
team_2:SetSize( 100, 50 )
team_2:SetText( “Rebel!” )
team_2.DoClick = function() frame:Close()
RunConsoleCommand( “team_2” )
end
end
concommand.Add( “team_menu”, set_team )
[/lua]
Tested and working.

Ok, Ill try that shortly, just need to tear my gf away from her sims… :s

At least give a good example of tabbing.

[lua]function set_team()
local frame = vgui.Create( “DFrame” )
frame:SetPos( 100, ScrH() / 2 )
frame:SetSize( 200, 210 )
frame:SetTitle( “Change Team” )
frame:SetVisible( true )
frame:SetDraggable( false )
frame:ShowCloseButton( true )
frame:MakePopup()

local team_1 = vgui.Create( "DButton", frame )
team_1:SetPos( 30, 30 )
team_1:SetSize( 100, 50 )
team_1:SetText( "Combine" )
team_1.DoClick = function()
	RunConsoleCommand( "team_1" )
	frame:Close()
end

local team_2 = vgui.Create( "DButton", frame )
team_2:SetPos( 30, 85 )
team_2:SetSize( 100, 50 )
team_2:SetText( "Rebels" )
team_2.DoClick = function()
	RunConsoleCommand( "team_2" )
	frame:Close()
end

end
concommand.Add( “team_menu”, set_team ) [/lua]

Well sorry… was just trying to help.