Calling dframe or other vgui element trough two function
5 replies, posted
I have a little problem for communicate with 2 Dframe on two different function.
for example I have this Derma Function
[CODE]function UITest()
local DPanelAmmoWindows = vgui.Create( "DFrame" )
DPanelAmmoWindows:SetPos( 100, 100 )
DPanelAmmoWindows:SetSize( 300, 200 )
DPanelAmmoWindows:SetTitle( "" )
DPanelAmmoWindows:SetVisible( true )
DPanelAmmoWindows:SetDraggable( true )
DPanelAmmoWindows:ShowCloseButton( false )
DPanelAmmoWindows:MakePopup()
local DButtonClose = vgui.Create( "DButton", DPanelAmmoWindows )
DButtonClose:SetPos( DPanelAmmoWindows:GetWide() / 2 - 30 , 165)
DButtonClose:SetText( "Close" )
DButtonClose:SetSize( 60, 23 )
----------------------------------------------------
DButtonClose.DoClick = function()
DermaPanel:Close()
end
----------------------------------------------------
end
-- End Of function UITest() --
concommand.Add("UiTesting", UITest)[/CODE]
and on other one I want to make closing the DermaPanel from UITest2 with the button " DButtonClose "
on UITest
[CODE]function UITest2()
local DermaPanel = vgui.Create( "DFrame" )
DermaPanel:SetPos( 10, 10)
DermaPanel:SetSize( 300, 500)
DermaPanel:SetTitle( " test" )
DermaPanel:SetVisible( true )
DermaPanel:SetDraggable( true )
DermaPanel:SetSizable(true)
DermaPanel:MakePopup()
end
-- End Of function UITest2() --
concommand.Add("UiTesting2", UITest2)[/CODE]
Thanks in advance.
Does it give any errors?
Try making DermaPanel global(Remove local), and make sure it's being called before UITest.
[QUOTE=wakeboarderCWB;42049094]Does it give any errors?
Try making DermaPanel global(Remove local), and make sure it's being called before UITest.[/QUOTE]
It seem to not working.
In overall to be more precise in what I say ,
I have this in one file in example Autorun/TestThisUI.Lua
There is no error with or without global same with local
I think my principal Panel " DPanelAmmoWindows " where is in
UITest() cannot read " DermaPanel " in UITest2()
[CODE]function UITest2()
local DermaPanel = vgui.Create( "DFrame" )
DermaPanel:SetPos( 10, 10)
DermaPanel:SetSize( 300, 500)
DermaPanel:SetTitle( " test" )
DermaPanel:SetVisible( true )
DermaPanel:SetDraggable( true )
DermaPanel:SetSizable(true)
DermaPanel:MakePopup()
end
-- End Of function UITest2() --
concommand.Add("UiTesting2", UITest2)
function UITest()
local DPanelAmmoWindows = vgui.Create( "DFrame" )
DPanelAmmoWindows:SetPos( 100, 100 )
DPanelAmmoWindows:SetSize( 300, 200 )
DPanelAmmoWindows:SetTitle( "" )
DPanelAmmoWindows:SetVisible( true )
DPanelAmmoWindows:SetDraggable( true )
DPanelAmmoWindows:ShowCloseButton( false )
DPanelAmmoWindows:MakePopup()
local DButtonClose = vgui.Create( "DButton", DPanelAmmoWindows )
DButtonClose:SetPos( DPanelAmmoWindows:GetWide() / 2 - 30 , 165)
DButtonClose:SetText( "Close" )
DButtonClose:SetSize( 60, 23 )
----------------------------------------------------
DButtonClose.DoClick = function()
DermaPanel:Close()
end
----------------------------------------------------
end
-- End Of function UITest() --
concommand.Add("UiTesting", UITest)[/CODE]
[lua]function UITest2()
DermaPanel = vgui.Create( "DFrame" )
DermaPanel:SetPos( 10, 10)
DermaPanel:SetSize( 300, 500)
DermaPanel:SetTitle( " test" )
DermaPanel:SetVisible( true )
DermaPanel:SetDraggable( true )
DermaPanel:SetSizable(true)
DermaPanel:MakePopup()
end
-- End Of function UITest2() --
concommand.Add("UiTesting2", UITest2)
function UITest()
local DPanelAmmoWindows = vgui.Create( "DFrame" )
DPanelAmmoWindows:SetPos( 100, 100 )
DPanelAmmoWindows:SetSize( 300, 200 )
DPanelAmmoWindows:SetTitle( "" )
DPanelAmmoWindows:SetVisible( true )
DPanelAmmoWindows:SetDraggable( true )
DPanelAmmoWindows:ShowCloseButton( false )
DPanelAmmoWindows:MakePopup()
local DButtonClose = vgui.Create( "DButton", DPanelAmmoWindows )
DButtonClose:SetPos( DPanelAmmoWindows:GetWide() / 2 - 30 , 165)
DButtonClose:SetText( "Close" )
DButtonClose:SetSize( 60, 23 )
----------------------------------------------------
DButtonClose.DoClick = function()
DermaPanel:Close()
end
----------------------------------------------------
end
-- End Of function UITest() --
concommand.Add("UiTesting", UITest)[/lua]
I removed local from DermaPanel and it works fine for me. If you're calling a variable/element from a separate function you need to make sure it's global.
[QUOTE=wakeboarderCWB;42052342][lua]function UITest2()
DermaPanel = vgui.Create( "DFrame" )
DermaPanel:SetPos( 10, 10)
DermaPanel:SetSize( 300, 500)
DermaPanel:SetTitle( " test" )
DermaPanel:SetVisible( true )
DermaPanel:SetDraggable( true )
DermaPanel:SetSizable(true)
DermaPanel:MakePopup()
end
-- End Of function UITest2() --
concommand.Add("UiTesting2", UITest2)
function UITest()
local DPanelAmmoWindows = vgui.Create( "DFrame" )
DPanelAmmoWindows:SetPos( 100, 100 )
DPanelAmmoWindows:SetSize( 300, 200 )
DPanelAmmoWindows:SetTitle( "" )
DPanelAmmoWindows:SetVisible( true )
DPanelAmmoWindows:SetDraggable( true )
DPanelAmmoWindows:ShowCloseButton( false )
DPanelAmmoWindows:MakePopup()
local DButtonClose = vgui.Create( "DButton", DPanelAmmoWindows )
DButtonClose:SetPos( DPanelAmmoWindows:GetWide() / 2 - 30 , 165)
DButtonClose:SetText( "Close" )
DButtonClose:SetSize( 60, 23 )
----------------------------------------------------
DButtonClose.DoClick = function()
DermaPanel:Close()
end
----------------------------------------------------
end
-- End Of function UITest() --
concommand.Add("UiTesting", UITest)[/lua]
I removed local from DermaPanel and it works fine for me. If you're calling a variable/element from a separate function you need to make sure it's global.[/QUOTE]
Thanks it working now , I made something wrong with a condition earlier.
It's better to make it local to file if you can.
[code]
local DermaPanel
function UITest2()
DermaPanel = vgui.Create( "DFrame" )
DermaPanel:SetPos( 10, 10)
DermaPanel:SetSize( 300, 500)
DermaPanel:SetTitle( " test" )
DermaPanel:SetVisible( true )
DermaPanel:SetDraggable( true )
DermaPanel:SetSizable(true)
DermaPanel:MakePopup()
end[/code]
Also you should add a sanity check to the button click:
[code]
DButtonClose.DoClick = function()
if DemaPanel:IsValid() then DermaPanel:Close() end
end[/code]
Sorry, you need to Log In to post a reply to this thread.