DFrame, Returning false if already open.

Hello all,

Just having some trouble with a menu I am making.
I only want one window to open when I press my button, but I can open 700 copies of the window.
However many times I click it, in correspondence the window will open.
So basically I just need to know if there is a DFrame:GetVisible? I know there is none on the wiki, but perhaps there is a longer pathway to getting it to return if it’s visible, if so then return false.

Thanks in advance.

, Ethan

if( DFrame ) then DFrame:Remove() DFrame = nil end

Strange,
I implemented it, now it won’t call the Frame at all.
I have named the functions right, and there is no errors in console.

won’t work if your dFrame is local.

[editline]12:45PM[/editline]

[lua]
– Close the menu if it’s already open.
if( mMenu ) then
mMenu:Remove();
mMenu = nil;
end

-- Start main vgui
mMenu = vgui.Create("DFrame");

[/lua]

Thanks for the let know,
Will test and get back to you when I get back home.

Thanks for the help.
P.S: I’m loving Venus Script :slight_smile:

It’s better to make it invisible, so you won’t have to rebuild the panel every time.

I use it that way Overv because my inventories get refreshed when they open the menu =P but here you go:

[lua]
if( mMenu ) then
mMenu:SetVisible(false)
else
mMenu:SetVisible(true)
end
[/lua]

That’s Overvs way.

It’s wierd, I’ve tried something like you wrote, if (dMenu) then, but it didn’t work. I have a usermessage hook that adds stuff to a menu when it receives a message, but I want it not to add the item to the menu if the user exits the menu before it’s finished. But doing what I mentioned above doesn’t work. It just tries to add it anyway, and in doing so gives you an error, something like “Tried to call ‘AddItem’, a nil value”.

DFrame’s are deleted when closed unless you set it not to.

DFrame:SetDeleteOnClose( false )

Averice’s code wouldn’t work, because it doesn’t check if the panel is visible or not, just if it exists.

Try this:

[lua]mMenu:SetVisible(!mMenu:IsVisible());[/lua]

oh yea lol… wow im having a stupid week

Here I was thinking that I was doing something wrong.
Thanks DarKSunrise.

Just tested, works like a charm.

& Thanks to the other fast replys

Sorry (Double Post, Just not sure if it ‘re-news’ the topic on edit).

But It the script decides itself when to work and when not to work.
It occasionally works, but I don’t know how to fix it when it “Glitches”.

Console Error;



autorun/client/Menu.lua:35: Tried to use invalid object (type Panel) (Object was NULL or not of the right type)*

Code:

[lua]SMenuButtonOptions.DoClick = function()

													if( SMenuButtonWindowOptions ) then  
													SMenuButtonWindowOptions:SetVisible( !SMenuButtonWindowOptions:IsVisible() );
 													SMenuButtonWindowOptions:Remove();  
													SMenuButtonWindowOptions = nil;  
													end 
													
													SMenuButtonWindowOptions = vgui.Create("DFrame")
													SMenuButtonWindowOptions:SetPos( ScrW() / 2 - 160, ScrH() / 2 - 155 )
													SMenuButtonWindowOptions:SetSize( 325, 270 )
													SMenuButtonWindowOptions:SetTitle("Options")
													SMenuButtonWindowOptions:SetDraggable(false)
													SMenuButtonWindowOptions:ShowCloseButton(true)
													SMenuButtonWindowOptions:PerformLayout()
													SMenuButtonWindowOptions.Paint = 	function()
		
																						surface.SetDrawColor(0, 0, 0, 200 )
																						surface.DrawRect( 0, 0, 	SMenuButtonWindowOptions:GetWide(), SMenuButtonWindowOptions:GetTall() )
																						
																						end
																											[/lua]

Replace this:
[lua]
if( SMenuButtonWindowOptions ) then
SMenuButtonWindowOptions:SetVisible( !SMenuButtonWindowOptions:IsVisible() );
SMenuButtonWindowOptions:Remove();
SMenuButtonWindowOptions = nil;
end
[/lua]
With this.
[lua]
if( SMenuButtonWindowOptions ) then
SMenuButtonWindowOptions:SetVisible( !SMenuButtonWindowOptions:IsVisible() );
end
[/lua]

I am still getting the same error.

My code within the error

[lua]
if( SMBW ) then
SMBW:SetVisible( !SMBW:IsVisible() );
end

SMBW = vgui.Create(“DFrame”)
SMBW:SetPos( ScrW() / 2 - 512, ScrH() / 2 - 384 )
SMBW:SetSize( 256, 256 )
SMBW:SetTitle(“Inventory”)
SMBW:SetDraggable(false)
SMBW:ShowCloseButton(true)
SMBW:SetVisible(true)
SMBW:MakePopup()
[/lua]

Actual line of code containing error:

[lua]
SMBW:SetVisible( !SMBW:IsVisible() );
[/lua]

Just do the basic method which is:

person push key -> function checks if boolean is true or false -> if boolean is true then do nothing -> if boolean is false then initiate window -> if window is closed then set boolean to false

Have a boolean that is either true or false depending on if a window already exist and if it true then do nothing but if it is false then initiate window.

Basic, simple and it works.

Sykore, there is such thing as too much white space XD

Oh and by the way, the way I think you have it now will check if it’s visible, if it is visible it will set it to invisible, and rebuild the whole thing. You may want to add a line like

if !SMBW:IsVisible() then return end

after you switch the visibility, so you’re not rebuilding a panel that’s invisible. It just wastes the computer’s effort.

You’d need a way to check if the player has actually built the panel atleast once since hes been on the server, otherwise it will all fail. Unless you use the first way i showed you which just stops duplicate menus showing up.

[lua]
– Close the menu if it’s already open.
if( mMenu ) then
mMenu:Remove();
mMenu = nil;
end

– Start main vgui
mMenu = vgui.Create(“DFrame”);
[/lua]

No, you do it like this:

[lua]function showMenu( )
if !mMenu then
// Build mMenu
end
mMenu:SetVisible( true )
end

function hideMenu( )
mMenu:SetVisible( false )
end[/lua]

But say he binds it to F1, how are you going to tell it what funciton to do…
like this?
[lua]
function GM:ShowHelp(ply)
if( !ply.Menu or ply.Menu = nil ) then
– menu open shit
ply.Menu = true;
else
– Menu close shit.
ply.Menu = false;
end
end
[/lua]