Hello to explain my situation let me show you what I am doing.
First, I create an editable panel and register it in cl_panel.lua:
local HUD_PANEL = {
Init = function( self )
local ply = LocalPlayer()
local w = ScrW()
local h = ScrH()
self:SetPos( w*(20/1000), h-h*(100/1000) )
self:SetSize( w*(420/1000), h*(85/1000) )
self.Body = self:Add( "Panel" )
self.Body:Dock( FILL )
function self.Body:Paint( w, h )
draw.RoundedBox( 0, 0, 0, w, h, Color( 0, 0, 0, 0) )
end
self.DBox= self.Body:Add( "DPanel" )
self.DBox:SetPos( 0, 0 )
self.DBox:SetSize( self.Body:GetTall()*(85/100),self.Body:GetTall()*(85/100) )
function self.DBox:Paint( w, h )
draw.RoundedBox( 4, 0, 0, w, h, Color( 255, 255, 255, 150) )
end
end
end
HUD_PANEL = vgui.Register( "HUD", HUD_PANEL, "EditablePanel" )
Next I utilize HUDPaint in cl_hud.lua. Let's call this Method 1:
local function HUD()
if( !IsValid( HudPanel ) ) then
HudPanel = vgui.Create( "HUD" )
end
...code snipped...
end
hook.Add( "HUDPaint" , "HUDPaint" , HUD )
For whatever reason when using Method 1 I am able to use DPanels and Panels in the Editable Panel HUD_PANEL. For the sake of FPS I wish to create "HUD" as follows. Let's call this Method 2:
local HudPanel = vgui.Create( "HUD" )
local function HUD()
...code snipped...
end
hook.Add( "HUDPaint" , "HUDPaint" , HUD )
When using Method 2 I am given the error "attmpted to index field 'DBox' (a nil valud)
This error is from me using a DPanel in HUD_PANEL.
How would I go about using Derma Panels in conjunction with vgui.Register? Is there a certain base panel other than EditablePanel? Also why am I able to use DPanels in Method 1 by not in Method 2?
did u include the file?
Yes, the files are auto included with init.lua. If it helps they are run as an addon and not a gamemode.
Sorry, you need to Log In to post a reply to this thread.