Hello there, if you can please help with something I'm making I'd deeply appreciate it.
[lua]
-- ...
function DrawVotingBooth()
local MainWindow = vgui.Create("DFrame")
MainWindow:SetPos(0,0)
MainWindow:SetSize(ScrW(),ScrH())
MainWindow:SetTitle('The Almighty Box!')
MainWindow:SetVisible(true)
MainWindow:MakePopup()
MainWindow.Paint=function()
-- draw.RoundedBox(2,0,0,ScrW(),ScrH(),Color(255,255,255,255))
end
if ( IsValid ( GetGlobalEntity('Candidate') ) == true ) then
local VoteI=vgui.Create('DButton',MainWindow)
VoteI:SetSize(ScrW() / 4 * 2, ScrH() / 6 * 2)
VoteI:SetPos(0,0)
VoteI:SetText('Mayor : '..
GetGlobalEntity('Mayor'):GetNWString('wrp_name'))
VoteI.Paint=function()
surface.SetDrawColor(255,0,0,255)
surface.DrawRect(ScrW() / 4, ScrH()/6, ScrW()/4*2,ScrH()/6*2)
end
VoteI.DoClick=function()
RunConsoleCommand('Vote','0')
MainWindow:Close()
chat.AddText(Color(255,0,0,255),'Thank you for Voting!')
end
else
local Run=vgui.Create('DButton',MainWindow)
Run:SetPos(0,22)
Run:SetSize(ScrW(),ScrH() / 2)
Run:SetText('Run for Office')
Run.Paint=function()
--surface.SetDrawColor(255,0,0,255)
--surface.DrawRect(0, 22, ScrW(),ScrH() / 2 - 22)
end
Run.DoClick=function()
chat.AddText(Color(255,0,0,255),'Morzh')
MainWindow:Close()
end
local Walk=vgui.Create("DButton",MainWindow) -- Lol
Walk:SetPos(0,ScrH() / 2)
Walk:SetSize(ScrW(), ScrH() / 2)
Walk:SetText("No thanks")
Walk.Paint=function()
--surface.SetDrawColor(255,0,0,255)
--surface.DrawRect(0,ScrH() - 22,ScrW(), ScrH() / 2 - 22)
end
Walk.DoClick=function()
MainWindow:Remove()
end
end
end
-- Stuff
concommand.Add('wrp_voting_booth',DrawVotingBooth)
[/lua]
The issue is that I cannot get the parent DFrame to close when I click the button to cancel out of it.
Try Close instead of Remove: [url]http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/indexc974.html[/url]
That's what I was using first, but it still took several clicks before it closed the box. It's funny though because with the first where you do elect to campaign for Office, the message being sent gets there the first click. I actually put that message there to debug it...
If it spams the Dframe you made. Make it SimpleUse.
By the way, to do that, ENT:SetUseType(SIMPLE_USE), or whatever you're using it on.
Can you please help? It still isn't resolved.
The thing is when I click the button it doesn't close, even when it is set to Close(), Remove() makes no difference. It always takes several clicks to register.
If you drag your dframe out of the way, are there more behind it?
[B]Change this:[/B]
[QUOTE=TheNerdPest14;39181320]
[CODE]function DrawVotingBooth()
local MainWindow = vgui.Create("DFrame")
MainWindow:SetPos(0,0)
MainWindow:SetSize(ScrW(),ScrH())
MainWindow:SetTitle('The Almighty Box!')
MainWindow:SetVisible(true)
MainWindow:MakePopup()
MainWindow.Paint=function()
-- draw.RoundedBox(2,0,0,ScrW(),ScrH(),Color(255,255,255,255))
end
if ( IsValid ( GetGlobalEntity('Candidate') ) == true ) then
local VoteI=vgui.Create('DButton',MainWindow)
VoteI:SetSize(ScrW() / 4 * 2, ScrH() / 6 * 2)
VoteI:SetPos(0,0)
VoteI:SetText('Mayor : '..
GetGlobalEntity('Mayor'):GetNWString('wrp_name'))
VoteI.Paint=function()
surface.SetDrawColor(255,0,0,255)
surface.DrawRect(ScrW() / 4, ScrH()/6, ScrW()/4*2,ScrH()/6*2)
end
VoteI.DoClick=function()
RunConsoleCommand('Vote','0')
MainWindow:Close()
chat.AddText(Color(255,0,0,255),'Thank you for Voting!')
end
else
local Run=vgui.Create('DButton',MainWindow)
Run:SetPos(0,22)
Run:SetSize(ScrW(),ScrH() / 2)
Run:SetText('Run for Office')
Run.Paint=function()
--surface.SetDrawColor(255,0,0,255)
--surface.DrawRect(0, 22, ScrW(),ScrH() / 2 - 22)
end
Run.DoClick=function()
chat.AddText(Color(255,0,0,255),'Morzh')
MainWindow:Close()
end
local Walk=vgui.Create("DButton",MainWindow) -- Lol
Walk:SetPos(0,ScrH() / 2)
Walk:SetSize(ScrW(), ScrH() / 2)
Walk:SetText("No thanks")
Walk.Paint=function()
--surface.SetDrawColor(255,0,0,255)
--surface.DrawRect(0,ScrH() - 22,ScrW(), ScrH() / 2 - 22)
end
Walk.DoClick=function()
MainWindow:Remove()
end
end
end
-- Stuff
concommand.Add('wrp_voting_booth',DrawVotingBooth)[/CODE]
[/QUOTE]
[B]To:[/B]
[CODE]function DrawVotingBooth()
local MainWindow = vgui.Create("DFrame")
MainWindow:SetPos(0,0)
MainWindow:SetSize(ScrW(),ScrH())
MainWindow:SetTitle('The Almighty Box!')
MainWindow:SetVisible(true)
MainWindow:MakePopup()
MainWindow.Paint=function()
-- draw.RoundedBox(2,0,0,ScrW(),ScrH(),Color(255,255,255,255))
end
if ( IsValid ( GetGlobalEntity('Candidate') ) == true ) then
local VoteI=vgui.Create('DButton',MainWindow)
VoteI:SetSize(ScrW() / 4 * 2, ScrH() / 6 * 2)
VoteI:SetPos(0,0)
VoteI:SetText('Mayor : '..
GetGlobalEntity('Mayor'):GetNWString('wrp_name'))
VoteI.Paint=function()
surface.SetDrawColor(255,0,0,255)
surface.DrawRect(ScrW() / 4, ScrH()/6, ScrW()/4*2,ScrH()/6*2)
end
VoteI.DoClick=function()
RunConsoleCommand('Vote','0')
RunConsoleCommand("MainWindowClose")
chat.AddText(Color(255,0,0,255),'Thank you for Voting!')
end
else
local Run=vgui.Create('DButton',MainWindow)
Run:SetPos(0,22)
Run:SetSize(ScrW(),ScrH() / 2)
Run:SetText('Run for Office')
Run.Paint=function()
--surface.SetDrawColor(255,0,0,255)
--surface.DrawRect(0, 22, ScrW(),ScrH() / 2 - 22)
end
Run.DoClick=function()
chat.AddText(Color(255,0,0,255),'Morzh')
RunConsoleCommand("MainWindowClose") -- call the console command
end
local Walk=vgui.Create("DButton",MainWindow) -- Lol
Walk:SetPos(0,ScrH() / 2)
Walk:SetSize(ScrW(), ScrH() / 2)
Walk:SetText("No thanks")
Walk.Paint=function()
--surface.SetDrawColor(255,0,0,255)
--surface.DrawRect(0,ScrH() - 22,ScrW(), ScrH() / 2 - 22)
end
Walk.DoClick=function()
RunConsoleCommand("MainWindowClose")
end
end
end
function MainWindowClose() --added a function to make the window close
MainWindow:Close()
end
concommand.add("MainWindowClose", MainWindowClose) --make a console command to close the window
concommand.Add('wrp_voting_booth',DrawVotingBooth)[/CODE]
this may work or it may be what _Undefined said. if you are editing your script while you are in the game and you save your script it will pop up in game, so each time you save your script in the script editor it opens up the menu. Thus you will have multiple menus open!
This works for me, hope it works for you. Good luck!
I apologize, as it clearly is that there are multiple Frames, it indeed was the error. I recall having a similar error not long ago, and feel very sorry having not remembered it sooner.
Sorry, you need to Log In to post a reply to this thread.