[DERMA] How do I connect one button to two frames?
8 replies, posted
So, I started to mess with derma yesterday, and it was really interesting. Until I came into to a problem. I made two frames, but I had no clue how I could make them both close at the same time. So I started to ask a few friends and eventually post it in the Garry's Mod Discussions, but I recieved no answer that actually worked. So now I'm here asking for help.
This is the code I currently have, there are no lua errors or anything.
[CODE]local Frame = vgui.Create( "DFrame" )
Frame:SetSize(200,1200)
Frame:SetTitle( "Wanker" )
Frame:SetPos(0,0)
Frame:SetVisible( true )
Frame:SetDraggable( false )
Frame:ShowCloseButton( true )
Frame:MakePopup()
Frame.Paint = function(self,w,h)
draw.RoundedBox(0,0,0,w,h, Color(32,36,47))
end
local close = vgui.Create("DButton", Frame)
close:SetSize(100,30)
close:SetPos(50,50)
close:SetText("Close")
close:SetTextColor(Color( 255,255,255))
close.Paint = function(self,w,h)
draw.RoundedBox(0,0,0,w,h, Color(41,128,185,250))
end
close.DoClick = function ()
close:Remove()
Frame:Remove()
gui.EnableScreenClicker(false)
net.Start("CS_MenuClosed")
net.SendToServer()
end
local Frame = vgui.Create("DFrame")
Frame:SetSize(1137,1200)
Frame:SetPos(783,0)
Frame:SetTitle ("Test")
Frame:SetVisible(true)
Frame:SetDraggable(false)
Frame:ShowCloseButton(true)
Frame:MakePopup()
Frame.Paint = function(self,w,h)
draw.RoundedBox(0,0,0,w,h, Color(32,36,47))
end
[/CODE]
And this is what the it looks like:
[IMG]http://images.akamai.steamusercontent.com/ugc/270599410806487365/C4103A03D8ED647186BEE7EB1F95C4A4F0A0DAE0/[/IMG]
Try moving the click.DoClick section to the bottom and possibly give the second Frame a different variable name
Yeah, the problem is you created two frames with the same variable name, meaning you overwrite it to close the old frame rather than the new one
Give both panels global variables, and do GlobalVar1:Remove() when the button is pressed for both panels.
[QUOTE=NiandraLades;50826627]Try moving the click.DoClick section to the bottom and possibly give the second Frame a different variable name[/QUOTE]
What do you mean with different variable name? Should I change the DFrame to something else? And if yes, then what?
[QUOTE=KingLeo;50826661]What do you mean with different variable name? Should I change the DFrame to something else? And if yes, then what?[/QUOTE]
[code]
local var1 = ...
local var2 = ...
[/code]
[QUOTE=whitestar;50826665][code]
local var1 = ...
local var2 = ...
[/code][/QUOTE]
[CODE]local Frame = vgui.Create( "DFrame" )
local var1 = ("Doge")
Frame:SetSize(200,1200)
Frame:SetTitle( "Wanker" )
Frame:SetPos(0,0)
Frame:SetVisible( true )
Frame:SetDraggable( false )
Frame:ShowCloseButton( true )
Frame:MakePopup()
Frame.Paint = function(self,w,h)
draw.RoundedBox(0,0,0,w,h, Color(32,36,47))
end
local Frame = vgui.Create("DFrame")
local var2 = ("Shiba")
Frame:SetSize(1137,1200)
Frame:SetPos(783,0)
Frame:SetTitle ("Test")
Frame:SetVisible(true)
Frame:SetDraggable(false)
Frame:ShowCloseButton(true)
Frame:MakePopup()
Frame.Paint = function(self,w,h)
draw.RoundedBox(0,0,0,w,h, Color(32,36,47))
end
local close = vgui.Create("DButton", Frame)
close:SetSize(100,30)
close:SetPos(50,50)
close:SetText("Close")
close:SetTextColor(Color( 255,255,255))
close.Paint = function(self,w,h)
draw.RoundedBox(0,0,0,w,h, Color(41,128,185,250))
end
close.DoClick = function ()
close:Remove()
Frame:Remove()
gui.EnableScreenClicker(false)
net.Start("CS_MenuClosed")
net.SendToServer()
end[/CODE]
I did this, but nothing is changed. You have to be a little more specific because I just started :c But thanks anyway
You never changed the variable. Look:
[CODE]
local Frame = vgui.Create( "DFrame" )
-- then you did this later
local Frame = vgui.Create("DFrame")
[/CODE]
Just change one of those Frame variables to be a different name
[editline]4th August 2016[/editline]
[CODE]
local Frame = vgui.Create( "DFrame" )
Frame:SetSize(200,1200)
Frame:SetTitle( "Wanker" )
Frame:SetPos(0,0)
Frame:SetVisible( true )
Frame:SetDraggable( false )
Frame:ShowCloseButton( true )
Frame:MakePopup()
Frame.Paint = function(self,w,h)
draw.RoundedBox(0,0,0,w,h, Color(32,36,47))
end
local OTHER_FRAME = vgui.Create("DFrame")
OTHER_FRAME:SetSize(1137,1200)
OTHER_FRAME:SetPos(783,0)
OTHER_FRAME:SetTitle ("Test")
OTHER_FRAME:SetVisible(true)
OTHER_FRAME:SetDraggable(false)
OTHER_FRAME:ShowCloseButton(true)
OTHER_FRAME:MakePopup()
OTHER_FRAME.Paint = function(self,w,h)
draw.RoundedBox(0,0,0,w,h, Color(32,36,47))
end
local close = vgui.Create("DButton", Frame)
close:SetSize(100,30)
close:SetPos(50,50)
close:SetText("Close")
close:SetTextColor(Color( 255,255,255))
close.Paint = function(self,w,h)
draw.RoundedBox(0,0,0,w,h, Color(41,128,185,250))
end
close.DoClick = function()
close:Remove()
OTHER_FRAME:Remove()
gui.EnableScreenClicker(false)
net.Start("CS_MenuClosed")
net.SendToServer()
end
[/CODE]
[editline]4th August 2016[/editline]
Variables are the simplest thing possible to know in Lua. If you don't understand them, it's probably not a good idea to even be touching derma yet.
[editline]4th August 2016[/editline]
What you were doing before was literally equivalent to this:
[CODE]
local var1 = 1
local var1 = 2
print( var1 ) -- This will obviously equal 2 because you literally just set it to 2 mate
-- Why do you expect it to still equal 1 if you set it to be something else?
[/CODE]
[QUOTE=MPan1;50826737]You never changed the variable. Look:
[CODE]
local Frame = vgui.Create( "DFrame" )
-- then you did this later
local Frame = vgui.Create("DFrame")
[/CODE]
Just change one of those Frame variables to be a different name
[editline]4th August 2016[/editline]
[CODE]
local Frame = vgui.Create( "DFrame" )
Frame:SetSize(200,1200)
Frame:SetTitle( "Wanker" )
Frame:SetPos(0,0)
Frame:SetVisible( true )
Frame:SetDraggable( false )
Frame:ShowCloseButton( true )
Frame:MakePopup()
Frame.Paint = function(self,w,h)
draw.RoundedBox(0,0,0,w,h, Color(32,36,47))
end
local OTHER_FRAME = vgui.Create("DFrame")
OTHER_FRAME:SetSize(1137,1200)
OTHER_FRAME:SetPos(783,0)
OTHER_FRAME:SetTitle ("Test")
OTHER_FRAME:SetVisible(true)
OTHER_FRAME:SetDraggable(false)
OTHER_FRAME:ShowCloseButton(true)
OTHER_FRAME:MakePopup()
OTHER_FRAME.Paint = function(self,w,h)
draw.RoundedBox(0,0,0,w,h, Color(32,36,47))
end
local close = vgui.Create("DButton", Frame)
close:SetSize(100,30)
close:SetPos(50,50)
close:SetText("Close")
close:SetTextColor(Color( 255,255,255))
close.Paint = function(self,w,h)
draw.RoundedBox(0,0,0,w,h, Color(41,128,185,250))
end
close.DoClick = function()
close:Remove()
OTHER_FRAME:Remove()
gui.EnableScreenClicker(false)
net.Start("CS_MenuClosed")
net.SendToServer()
end
[/CODE]
[editline]4th August 2016[/editline]
Variables are the simplest thing possible to know in Lua. If you don't understand them, it's probably not a good idea to even be touching derma yet.
[editline]4th August 2016[/editline]
What you were doing before was literally equivalent to this:
[CODE]
local var1 = 1
local var1 = 2
print( var1 ) -- This will obviously equal 2 because you literally just set it to 2 mate
-- Why do you expect it to still equal 1 if you set it to be something else?
[/CODE][/QUOTE]
Thanks man. Though you forgot to add
[CODE]Frame:Remove()[/CODE] :c
But thanks so much.
Sorry, you need to Log In to post a reply to this thread.