Cannot create custom derma control

Hi,

I’m trying to make a dead simple progress bar control for Derma. I know there’s a built in one but I’d like one that I can easily modify.

I wrote the following code:



YMProgressBar.m_color = nil
function YMProgressBar:Init()
	self.m_value = 0
	self.m_bgcolor = Color(0,0,0,0)
	self.m_color = Color(255,255,255)
end
function YMProgressBar:SetValue(i)
	self.m_value = i
end
function YMProgressBar:SetBackgroundColor(color)
	self.m_bgcolor = color
end
function YMProgressBar:SetForegroundColor(color)
	self.m_color = color
end
function YMProgressBar:Paint()
	local width = self:GetWide()
	local height = self:GetTall()
	
	surface.SetDrawColor(self.m_bgcolor)
	surface.DrawRect(0, 0, width, height)
	
	surface.SetDrawColor(self.m_color)
	surface.DrawRect(0, 0, width*self.m_value, height)
	
	return true
end
vgui.Create("YMBar", YMProgressBar, "DPanel")


But when I try to actually create the control:



progress = vgui.Create("YMBar")
progress:SetSize(sw, MAPVOTE.config.progressBarHeight)
progress:SetPos(0, cy-(MAPVOTE.config.progressBarHeight/2))


I get an error saying “Warning: vgui.Create failed to create the VGUI component (YMBar)”

I’m sure I’ve made a really stupid mistake but I just can’t find it. Help would be greatly appreciated, thanks!

YM

You need to use vgui.Register not vgui.Create in the first block of code to create the YMBar panel class.

Oh my god I’m dumb. Thank you!