Panel:Init() hook

Hello everyone, I am trying to us the Panel:Init() hook, but i have no idea how to use it. The code is generated with Derma Designer so the variable names are useless
[LUA]
– Lua generated by DermaDesigner

local DButton92
local DFrame4

DFrame4 = vgui.Create(‘DFrame’)
DFrame4:SetSize(179, 157)
DFrame4:SetPos(49, 71)
DFrame4:SetTitle(‘Test’)
DFrame4:SetSizable(true)
DFrame4:SetDeleteOnClose(false)
DFrame4:MakePopup()

funtion DFrame4:Init()
DButton92 = vgui.Create(‘DButton’)
DButton92:SetParent(DFrame4)
DButton92:SetSize(70, 25)
DButton92:SetPos(29, 39)
DButton92:SetText(‘Test’)
end
[/LUA]

thank you in advance.

You shouldn’t do that.

Also init is called when you create the frame so changing it afterwarts is useless.

Just parent the button without using the init function…

I just used an if statement do get what i wanted it to do. But I’m not sure if it is needed.
Code:(its for a calculator but this only the derma file)
[Lua]if Start==0 then
BuildFirstFunctions()
Start = 1
end
[/Lua]
is the if statement redundant?

It’s not a hook, it’s an actual function.

I think this is what you’re after regarding Panel:Init()

[lua]

local PANEL = {}

function PANEL:Init()
self:SetSize(500,500)
self:SetTitle(“My Panel”)
self:MakePopup()
self:Center() // Centres it to the middle of the screen. You should always do this AFTER setting the size.

self.MyDLabel = vgui.Create("DLabel",self)
self.MyDLabel:SetText("Hello world!")
self.MyDLabel:SizeToContents()
self.MyDLabel:SetPos(50,50)

end

vgui.Register(“MyFrameName”,PANEL,“DFrame”) // Name of your frame, the table and what sort of Derma panel you’re after. This can be DPanel etc.
[/lua]
And afterwards, you can do:

[lua]
vgui.Create(“MyFrameName”)
[/lua]

[editline]02:14PM[/editline]

Should have explained that the second argument of the object (in this case a DLabel) is the parent. This explains the lack of SetParent() being used.