Calling DFrame:SetVisible outside of derma function

I have this derma panel and I made 2 functions outside of the derma’s function that set’s it to visible and not visible. But It doesn’t work, I want to be able to call if it should be visible or not outside of the derma, how would I do this?



function ActMenu()
	Frame = vgui.Create( "DFrame" )
	Frame:SetSize( 328, 101 )
	Frame:Center()
	Frame:SetTitle("")
	Frame:MakePopup()
	Frame:SetVisible(true)
	Frame:SetDraggable(false)
	Frame:SetBackgroundBlur(true)
	Frame:ShowCloseButton(false)
		
	Frame.Paint = function( self, w, h ) 
		draw.RoundedBox( 0, 0, 0, w, h, Color( 30, 30, 30, 220 ) )
	end
end

function FrameYes()
	Frame:SetVisible(true)
end
function FrameNo()
	Frame:SetVisible(false)
end


Have you tried putting



local Frame


At the very top?

[editline]4th November 2016[/editline]

Technically since it’s a global function it should be working anyway at the moment… odd

can we have all of your script ? cause vgui libs can are only client side. So i want to know how did you trigger your DFrame ^^"

Remove “Frame:SetVisible(true)” from ActMenu and are you sure FrameYes and FrameNo are being called?

So if you just want to masque DFrame for close it, you need to look at Frame:Remove().

but… this scripte to make a visible frame, or an invisible frame( why ?)

(i don’t know if its optimised or not… but its a way ^^")

ServerSide



print("Test.LUA is loaded.")
-- this part off code is juste here to trigger on/off function so, don't care off this ^^---------------
	-- For trying your On fuction : type /On in tchat
	-- For trying your Off fuction : type /off in tchat

if (SERVER) then	
	util.AddNetworkString( "TEST_chanel" )
	function chatCommand( ply, text, public )
		if (string.sub(text, 1, 3) == "/on") then 
			net.Start( "TEST_chanel" )
			net.WriteBool( true )
			net.Send( ply )
		elseif (string.sub(text, 1, 4) == "/off") then 
			net.Start( "TEST_chanel" )
			net.WriteBool( false )
			net.Send( ply )
		end
		return(false)
	end
	
	hook.Add( "PlayerSay", "chatCommand", chatCommand );
end


Client side “emulated”



-- VGUI is client side lib.
if (CLIENT) then
	net.Receive( "TEST_chanel", function( len, ply )
	local Bool = net.ReadBool()
---------------------------------------------------------------------------------------------------------	
		-- Funcs define
		function ActMenu(Argument)
		local Frame = vgui.Create( "DFrame" )
			Frame:SetSize( 328, 101 )
			Frame:Center()
			Frame:SetTitle("test")
			Frame:SetDraggable( true )
			Frame:SetVisible( Argument )
			Frame:ShowCloseButton( true )
			Frame:SetBackgroundBlur( true )
			Frame:MakePopup()
			Frame.Paint = function( self, w, h ) draw.RoundedBox( 0, 0, 0, w, h, Color( 30, 30, 30, 220 ) ) end
		end
	
		function FrameYes()
			ActMenu(true)
		end
		
		function FrameNo()
			ActMenu(false)
		end
	
		-- here, we call functions. I called them with a hook (triggered server side).
		-- but i will try to emulat a call from client side.
		if Bool == true then FrameYes() end
		if Bool == false then FrameNo() end
	end)	
end


or direclty from a net channel



-- VGUI is client side lib.
if (CLIENT) then
	net.Receive( "TEST_chanel", function( len, ply )
		function ActMenu()
		local Frame = vgui.Create( "DFrame" )
			Frame:SetSize( 328, 101 )
			Frame:Center()
			Frame:SetTitle("test")
			Frame:SetDraggable( true )
			Frame:SetVisible( net.ReadBool() )
			Frame:ShowCloseButton( true )
			Frame:SetBackgroundBlur( true )
			Frame:MakePopup()
			Frame.Paint = function( self, w, h ) draw.RoundedBox( 0, 0, 0, w, h, Color( 30, 30, 30, 220 ) ) end
		end	
		ActMenu()
	end)	
end


try putting print statements everywhere, and check if the frame is valid in each function. If the 3 functions are all within the same scope, it should theoretically work. I’m thinking we haven’t been given all 100% of the information we need to know to help

I actually tried this code out and it didn’t work for me. Typing /on and /off doesn’t bring up the panel however the script is being loaded and included.

That’s because of this part:



-- Funcs define
		function ActMenu(Argument)
		local Frame = vgui.Create( "DFrame" ) // This is inside the function 


See how the local Frame part is in the function? That makes it local to the function, meaning you can only access the frame in that function. It’s an incredibly basic variable concept. Just move it out of that function and it’ll let you change it.

Mmmm DFrame aren’t var or array, right ? So they are Entity ? Can we use meta to define them in absolut ? Like npc with ENT:blabla, ENT:fsff ?

Cause my scripte juste créat a visible DFrame, and another UnVisible. But can’t rewrite DFrame.

** Frame:SetVisible( tobool(Argument) ) **

or for second

**
local Bool = net.ReadBool()
Frame:SetVisible( tobool(Bool ) )
**

i try the second but not first

but if you wont creat a DFrame unvisible but set it to unvisible, you need to creat them again (overwit older) and creat a new DFrame with false bool like (i said it some MSG ago ^^ Frame:Remove() ) :


print("Test.LUA is loaded.")
-- this part off code is juste here to trigger on/off function so, don't care off this ^^---------------
	-- For trying your On fuction : type /On in tchat
	-- For trying your Off fuction : type /off in tchat

if (SERVER) then	
	util.AddNetworkString( "TEST_chanel" )
	function chatCommand( ply, text, public )
		if (string.sub(text, 1, 3) == "/on") then 
			net.Start( "TEST_chanel" )
			net.WriteBool( true )
			net.Send( ply )
		elseif (string.sub(text, 1, 4) == "/off") then 
			net.Start( "TEST_chanel" )
			net.WriteBool( false )
			net.Send( ply )
		end
		return(false)
	end
	
	hook.Add( "PlayerSay", "chatCommand", chatCommand );
end


-- VGUI is client side lib.
if (CLIENT) then
	net.Receive( "TEST_chanel", function( len, ply )
	local Bool = net.ReadBool()
---------------------------------------------------------------------------------------------------------	
		-- Funcs define
		
		-- Frame are note a with "local" but is same of local cause she is on a function.
		function ActMenu(Argument)
			 -- if created, Frame is removed and re created with desired SetVisibile( bool ). If not created, Frame:Remove() is skiped.
			 -- Without that, you got a nil error type cause Frame dosent exist.
			if IsValid(Frame) then Frame:Remove() end
			
			-- now, we creat or recreat frame
			Frame = vgui.Create( "DFrame" )
			Frame:SetSize( 328, 101 )
			Frame:Center()
			Frame:SetTitle("test")
			Frame:SetDraggable( true )
			Frame:SetVisible( tobool(Argument) )
			Frame:ShowCloseButton( true )
			Frame:SetBackgroundBlur( true )
			Frame:MakePopup()
			Frame.Paint = function( self, w, h ) draw.RoundedBox( 0, 0, 0, w, h, Color( 30, 30, 30, 220 ) ) end	
		end
	
		function FrameYes()
			ActMenu(true)
		end
		
		function FrameNo()
			ActMenu(false)
		end
	
		-- here, we call functions. I called them with a hook (triggered server side).
		-- but i will try to emulat a call from client side.
		if Bool == true then FrameYes() end
		if Bool == false then FrameNo() end
	end)	
end


ps : its probably loaded on the server at start. But look at the clientside. if doesn’t work, its for that. (reload scripte to make it work with client… mmm easy way is make a scripte edit and sav =p )

I would wager vgui elements AREN’T entities, but rather, part of the vgui library.

snip~~ Figured out that the file wasn’t loading correctly so typing “/on” wasn’t bringing it up.