menu help

[lua]concommand.Add( “+menu”, function()
local weapon = vgui.Create( “DFrame” )
weapon:SetPos( ScrW()*0.36, ScrH()*0.30 )
weapon:SetSize( 320, 450 )
weapon:SetTitle( “Bonk-Mart” )
weapon:SetVisible( true )
weapon:SetDraggable( false )
weapon:ShowCloseButton( true )
weapon:MakePopup()
end)

concommand.Add( “-menu”, function()
if weapon then
weapon:Close()
weapon = nil
end
end)[/lua]

How do I make the “-menu” command close the menu? I don’t know how to have it call it out of the first function.

weapon is only local to the function for +menu, local variables can only be indexed where they are declared. Global or making the dframe before, then toggle visibility is the only way I think.

Indeed. I would declare the dframe outside of the console command, as I do not like having too many global variables.

This is confusing me, can someone tell me how to do it or something? lol, I gotta get this done.

[lua]local weapon = vgui.Create( “DFrame” )
weapon:SetPos( ScrW()*0.36, ScrH()*0.30 )
weapon:SetSize( 320, 450 )
weapon:SetTitle( “Bonk-Mart” )
weapon:SetDraggable( false )
weapon:ShowCloseButton( true )
weapon:MakePopup()
weapon:SetVisible( false )

function ShowMenu()
    weapon:SetVisible( true )
end

function HideMenu()
    weapon:SetVisible( false )
end

concommand.Add( “+menu”, ShowMenu)

concommand.Add( “-menu”, HideMenu)
[/lua]

You get the idea.

ohh well it’s 5:13 AM where I live so, I’m not thinking clearly lol. I’ll try that, thanks :slight_smile:

[editline]05:17AM[/editline]

That’s not going to work. That menu thing that is there isn’t the entire menu. I’ll pm you the entire code for it if you want.

[editline]05:21AM[/editline]

meh

Feel free to pm me.

Never mind, Fixed :smiley: