Toggle derma panel with SetVisible

I must be using this wrong. It goes away fine but never comes back. I’ve read through a bunch of threads but am still not understanding why this doesn’t work. I am creating this function just inside the create panel function at the very end. What am I missing or what should I read up on… There is probably some fundamental concept I am missing…

http://forum.facepunch.com/showthread.php?t=1412140&highlight=Toggle+panel+SetVisible

http://forum.facepunch.com/showthread.php?t=1357928

https://facepunch.com/showthread.php? t=1413517&highlight=SetVisible+toggle


function togglepanel ()


	if 		PanelTable.base:IsVisible()	then
			PanelTable.base:SetVisible(false)
	else
			PanelTable.base:SetVisible(true) 
			end		
end  

are you trying to call this in a Think or Paint hook attached to the panel?
Think and Paint are not called when a panel is not visible (using setvisible)


Panel:SetVisible(not Panel:IsVisible())

I don’t think the above code will fix your problem but it optimizes it faster and saves lines.

That’s why it won’t appear… So the only way is to make a console command that literally sets the panel variable to visible? Would that work? I

No way.
Just use this:


hook.Remove("Think","HidePanelCode")
hook.Add("Think","HidePanelCode",function()
if (IsValid(thepanel)) then
-- panel stuff here, such as SetVisible
else
hook.Remove("Think","HidePanelCode")
end
end)

Call it inside the function where you create the frame.

When you say panel stuff do you mean just the base code for the actual panel parameters or everything Ike the tabs and buttons?

Wherever you create your DFrame.
basically somewhere in the function where you have this:


local thepanel = vgui.Create("DFrame")

EDIT:
Changed DPanel to DFrame, sorry, but the same applies to DPanels as well

I’m still learning about hooks… Basically toggle this to a key in game I need to make a concommand and the call the hook?

What? I literally explained everything you need to do…

Where do you actually declare a key or consolecommand that makes this hook function actually happen? That’s what I meant…

Hooks are not always triggered by keys or console commands.
Research something if you don’t knwo what it means first

The Think hook

[editline]8th October 2015[/editline]

Nevermind. I know what you’re trying to do now.
Use this to create the console command.
Set the function to a function that will set the panel as visible.
Example:

(Clientside)


local thepanel = vgui.Create("DFrame")

concommand.Add("openpanel",function()
thepanel:SetVisible(true)
end)

Thanks for sticking with me. I did this at the bottom of my panel function literally before it ends.


function togglemypanel ()
	if 		PanelTable.base:IsVisible(true)
				then
			PanelTable.base:Hide()
			gui.EnableScreenClicker( false )
	else
			PanelTable.base:Show()
			gui.EnableScreenClicker( true )
			end		
end


I needed to be able to click the panel so I have the gui.EnableScreenClicker set there as well, and at the beginning when I create the panel (because I’m not using the toggle button to actually ‘create’ the panel).

Future whoever is trying to do this, put this function right at the end (just before the last “end” of your panel function)

Now I will put some SEO stuff so it won’t be so fucking hard to find this because all the other threads weren’t as clear as I was looking for.

how do I make toggle derma panel button press hide SetVisible show.

not, the SetMouseInput function never worked for me but gui.Enablescreenclicker worked fine everytime.