function dermatest()
local frame1 = vgui.Create("DFrame")
frame1:SetPos(200,200)
frame1:SetSize(300,200)
frame1:SetTitle("Kill Yourself!")
frame1:SetDraggable(false)
frame1:ShowCloseButton(false)
frame1:MakePopup()
local Button1 = vgui.Create("DButton")
Button1:SetPos(100,150)
Button1:SetSize(100,50)
Button1:SetText("Kill Yourself!")
Button1.DoClick = function()
RunConsoleCommand("kill")
frame1:Remove()
Button1:Remove()
end
end
I simply can't figure out whats wrong with it.
I can't.
first off, use [lua] brackets to make it esier to read
[CODE]function dermatest()
local frame1 = vgui.Create("DFrame")
frame1:SetPos(200,200)
frame1:SetSize(300,200)
frame1:SetTitle("Kill Yourself!")
frame1:SetDraggable(false)
frame1:ShowCloseButton(false)
frame1:MakePopup()
local Button1 = vgui.Create("DButton")
Button1:SetPos(100,150)
Button1:SetSize(100,50)
Button1:SetText("Kill Yourself!")
Button1.DoClick = function()
RunConsoleCommand("kill")
frame1:Remove()
Button1:Remove()
end
end
[/CODE]
first i can see that you didnt parent your button to the frame, do this:
[CODE] local Button1 = vgui.Create("DButton", [B]frame1[/B])
Button1:SetPos(100,150)
Button1:SetSize(100,50)
Button1:SetText("Kill Yourself!")
Button1.DoClick = function()
RunConsoleCommand("kill")
frame1:Remove()
[U]Button1:Remove()[/U]
end[/CODE]
if you parent your button to the frame, removing the frame removes the button
also, you need to place this in lua/autorun/client and make those folders if they dont exist, cause derma is run strictly client side
this is your final code:
[CODE]function dermatest()
local frame1 = vgui.Create("DFrame")
frame1:SetPos(200,200)
frame1:SetSize(300,200)
frame1:SetTitle("Kill Yourself!")
frame1:SetDraggable(false)
frame1:ShowCloseButton(false)
frame1:MakePopup()
local Button1 = vgui.Create("DButton", frame1)
Button1:SetPos(100,150)
Button1:SetSize(100,50)
Button1:SetText("Kill Yourself!")
Button1.DoClick = function()
RunConsoleCommand("kill")
frame1:Remove()
end
end
concommand.Add("blah", dermatest)
[/CODE]
[noparse][lua]code goes here[/lua][/noparse]
How do you know there's something wrong with it? Are you getting an error? Is it not showing up? Is it not killing you when you press the button? You're being a bit vague.
We could do with seeing more code than just the function itself. How are you executing this function, via console command?
All I can see that might be wrong is that your button isn't parented to the frame. That is, you want vgui.Create("DButton", frame1) rather than vgui.Create("DButton").
awww.... all you did is repeat what i did with a golden name behind you :(
i will just do what i normally do :
/\
|
| what he said :D
/
---
I had this problem before and the way I solved it was to remove 'local', so in other words try this:
[lua]
function dermatest()
frame1 = vgui.Create("DFrame")
frame1:SetPos(200,200)
frame1:SetSize(300,200)
frame1:SetTitle("Kill Yourself!")
frame1:SetDraggable(false)
frame1:ShowCloseButton(false)
frame1:MakePopup()
Button1 = vgui.Create("DButton", DFrame)
Button1:SetPos(100,150)
Button1:SetSize(100,50)
Button1:SetText("Kill Yourself!")
Button1.DoClick = function()
RunConsoleCommand("kill")
frame1:Remove()
Button1:Remove()
end
end
[/lua]
And as stated above your DButton wasnt rigged to DFrame.
[QUOTE=Ningaglio;20174103]awww.... all you did is repeat what i did with a golden name behind you :(
i will just do what i normally do :
/\
|
| what he said :D
/
---[/QUOTE]
You must have posted while I was typing. Either way you got there first, so clocks for me. Drives home the point further, as well.
[QUOTE=Jazora;20174232]
[lua]
function dermatest()
frame1 = vgui.Create("DFrame")
frame1:SetPos(200,200)
frame1:SetSize(300,200)
frame1:SetTitle("Kill Yourself!")
frame1:SetDraggable(false)
frame1:ShowCloseButton(false)
frame1:MakePopup()
Button1 = vgui.Create("DButton", DFrame)
Button1:SetPos(100,150)
Button1:SetSize(100,50)
Button1:SetText("Kill Yourself!")
Button1.DoClick = function()
RunConsoleCommand("kill")
frame1:Remove()
Button1:Remove()
end
end
[/lua][/QUOTE]
Why the hell are you parenting "Button1" to "DFrame". You should use frame1.
Second, why are you using "Remove()" when there is a really simple way to close a derma panel: [lua]DermaPanel:SetVisible( false )[/lua]As for your menu delete "DermaPanel" and put [B]"frame1"[/B]. There is no need of removing [B]button1[/B] too.
[QUOTE=lonewolf2;20175229]Why the hell are you parenting "Button1" to "DFrame". You should use frame1.
Second, why are you using "Remove()" when there is a really simple way to close a derma panel: DermaPanel:SetVisible( false )As for your menu delete "DermaPanel" and put "button1". There is no need of removing frame1 too.[/QUOTE]
Yep you are correct Lonewolf, I only focused on the 'locals' without taking into consideration the other errors, here is the complete script:
[lua]
function dermatest()
frame1 = vgui.Create("DFrame")
frame1:SetPos(200,200)
frame1:SetSize(300,200)
frame1:SetTitle("Kill Yourself!")
frame1:SetDraggable(false)
frame1:ShowCloseButton(false)
frame1:MakePopup()
Button1 = vgui.Create("DButton", frame1)
Button1:SetPos(100,150)
Button1:SetSize(100,50)
Button1:SetText("Kill Yourself!")
Button1.DoClick = function()
RunConsoleCommand("kill")
frame1:SetVisible( false )
end
end
[/lua]
Also you dont need to remove 'Button1' as its now parented to 'frame1', so just removing 'frame1' will do it.
Oh right, I forgot to close frame1. My bad.
Ok, i'm having another problem, when i put a code in autorun, it won't... well, autorun.
heres the code:
[lua] local button1 = vgui.Create("DButton")
button1:SetPos(350,50)
button1:SetSize(100,50)
button1:SetText("Kill Yourself!")
button1.DoClick = function()
RunConsoleCommand("kill")
end[/lua]
i don't get it it's supposed to autorun if it's in the autorun foler.
lol?
Sorry, you need to Log In to post a reply to this thread.