DNumSlider

Hi. If I have a DNumSlider and I have code so when a button is pressed the slider is made.

Here is what I have.

[lua]
TestB.DoClick = function()

	if MyBox:GetSelectedItems() and MyBox:GetSelectedItems()[1] then
		
		local Slider = vgui.Create( "DNumSlider", Derma )
		Slider:Center()
		Slider:SetSize( 150, 100 )
		Slider:SetText( MyBox:GetSelectedItems()[1]:GetValue() )
		Slider:SetMin( 0 )
		Slider:SetMax( 10 )
		Slider:SetDecimals( 0 )
		Slider:SetConVar( "TestConVar" )
		
	end
end

[/lua]

When you run this code, it keeps making new sliders. How do I make it so …

  1. The Slider Updates
    or
  2. The slider is removed and gets a new one

[lua]if not Slider then
– your code
else
Slider:SetValue(something)
end
[/lua]

If I understood correctly…

NonSense, that dosent work, just tested it and tested before.

It still makes a new one.

is there any thing in derma that will determine if Slider exists? Like …

[lua]

if Slider:Exists( true ) then
– blah
else
– blah1
end
[/lua]

Just set a bool to true if the slider has been created. The code I posted should work actually; maybe try declaring the slider globally (remove the local).

Thanks. Making it global worked.