I made a derma menu with only two buttons, but when I press the close button on the menu, the two buttons stay there... How can I fix this? Here is the code:
[CODE]function set_team()
local teammenu = vgui.Create( "DFrame" )
teammenu:SetPos( 50,50 )
teammenu:SetSize( 200, 250 )
teammenu:SetTitle( "ODWars Team Selection" )
teammenu:SetVisible( true )
teammenu:SetDraggable( false )
teammenu:ShowCloseButton( true )
teammenu:MakePopup()
local teamabtn = vgui.Create( "DButton", TeamA )
teamabtn:SetPos( 20, 25 )
teamabtn:SetSize( 125, 30 )
teamabtn:SetText( "Team A" )
teamabtn.DoClick = function()
RunConsoleCommand( "team_a" )
end
local teambbtn = vgui.Create( "DButton", TeamB )
teambbtn:SetPos( 20, 50 )
teambbtn:SetSize( 125, 30 )
teambbtn:SetText( "Team B" )
teambbtn.DoClick = function()
RunConsoleCommand( "team_b" )
end
end
concommand.Add( "set_team", set_team )[/CODE]
You were parenting your buttons wrong.
Instead of doing what you did you need to put the frame name where you had TeamA and TeamB
[lua]
//Correct
local teamabtn = vgui.Create( "DButton", teammenu )
//Wrong
local teamabtn = vgui.Create( "DButton", TeamA )
[/lua]
[lua]
function set_team()
local teammenu = vgui.Create( "DFrame" )
teammenu:SetPos( 50,50 )
teammenu:SetSize( 200, 250 )
teammenu:SetTitle( "ODWars Team Selection" )
teammenu:SetVisible( true )
teammenu:SetDraggable( false )
teammenu:ShowCloseButton( true )
teammenu:MakePopup()
local teamabtn = vgui.Create( "DButton", teammenu )
teamabtn:SetPos( 20, 25 )
teamabtn:SetSize( 125, 30 )
teamabtn:SetText( "Team A" )
teamabtn.DoClick = function()
RunConsoleCommand( "team_a" )
end
local teambbtn = vgui.Create( "DButton", teammenu )
teambbtn:SetPos( 20, 50 )
teambbtn:SetSize( 125, 30 )
teambbtn:SetText( "Team B" )
teambbtn.DoClick = function()
RunConsoleCommand( "team_b" )
end
end
concommand.Add( "set_team", set_team )
[/lua]
Oh I just forgot to add a parent on the buttons to the panel!
Sorry, you need to Log In to post a reply to this thread.