Derma updating! How does it works?!

Hello, i’ve been struggling the whole day with derma. I tryed all what i could after searching for different functions and posts

I have 2 different issues over here.
* The slider value ( The one circled in green ) will not update when the slider is moving, or if i go by replacing the text it wont move the slider. Althought it does when closing and re opening because the idea is storing that value for a while

  * The Red text wont update either, I tried using refresh function with *Frame* and with *label* variables ( took the local out first, of course ). But it wont change anything at all in the derma.

A bit more visual for if i’m being clear enought. The yelow represents the aproximate value on the slider, the red the min and max values. Then we got the circle which should have text updating.

[lua]
function ENT:Think()

if label:IsVisible() then 

	labelText = "ref"
	label:Refresh(true)
end

end

function Derma()

labelText = "First Scan the vessel before displaying any data!"
local Frame = vgui.Create( "DFrame" )
	Frame:SetPos( 5, 5 )
	Frame:SetSize( ScrW()/2.5, ScrH()/2.5 )
	Frame:SetTitle( "Name window" )
	Frame:SetVisible( true )
	Frame:SetDraggable( true )
	Frame:Center()
	Frame:SetPos( ScrW()/2 , ScrH()/2)
	Frame:ShowCloseButton( true )
	Frame:MakePopup()

local slider = vgui.Create("DNumSlider")
	slider:SetParent(Frame)
	slider:SetSize( ScrW()/5, 10)
	slider:SetPos(50,330)
	slider:SetMin(-100)
	slider:SetMax(100)
	slider:SetDecimals(0)
	slider:SetValue(sliderValue)
	slider:SetText("Scan elevation")
	slider.ValueChanged = function(pSelf, fValue)

	sliderValue = fValue
	Frame:Refresh(true)

end

local button = vgui.Create( "DButton" )
	button:SetParent(Frame)
	button:SetPos( 450, 300 )
	button:SetSize(ScrW()/10,ScrH()/20)
	button:SetText("Scan!")
	
	button.DoClick = function()


		net.Start('ScanExecute')
		net.WriteInt(sliderValue,8)
		net.SendToServer()

	end

label = vgui.Create("DLabel")
	label:SetParent(Frame)
	label:SetPos(50,50)
	label:SetText(labelText)
	label:SetSize(300,100)
	label:SetTextColor(Color(255,50,50,255))

local checkbox = vgui.Create("DCheckBoxLabel")
	checkbox:SetParent(Frame)
	checkbox:SetPos(450,270)
	checkbox:SetText("Enable Scan Visualization")
	checkbox:SetValue( ticked )
	checkbox:SizeToContents()

	function checkbox:OnChange( val )

		if val then

			ticked = true
			
		else

			ticked = false
			
		end

	end

end[/lua]

Thanks for taking a time for reading this :slight_smile:

What have you done so far to solve your issue? Ever consider https://wiki.garrysmod.com/page/Net_Library_Usage

The easy way to do this is to do things like this is to save the things you want to update outside the function (but not globally!)

client-side



local my_updateable_element1, my_updateable_element2, ...

function make_my_gui()
    my_updateable_element1 = vgui.Create("DLabel")
    my_updateable_element2 = vgui.Create("DButton")
    my_updateable_element2.DoClick = function(self)
        net.Start("foo")
        net.SendToServer()
    end
    :
    :
end
make_my_gui()

net.receive("bar",function()
    print("I received a message from the server!")
    my_updateable_element1:SetText(net.ReadString())
end)


server-side



util.AddNetworkString("foo")
util.AddNetworkString("bar")

net.Receive("foo",function(ln,ply)
    print("I received a message from the client!")
    net.Start("bar")
    net.WriteString("Oh snap, this label updated!")
    net.Send(ply)
end)


After reviewing your code, there are a couple things you should consider changing.

First thing being that

Panel:Refresh doesn’t do what you’re trying to do I assume. If you read the description of the function, you can see what it actually does. (Refreshes HTML panels)

Second, for your label, you’re not actually updating the text of the label; you’re simply updating a variable. Meaning after you update the variable, you’re gonna need to update the text as well by calling

DLabel:SetText afterwards. “SetText” isn’t called every frame, hence why it doesn’t change when you change the variable. Alternatively, you could stick it in a think hook for the label and it’ll automatically update the text of the label when you change the variable (since Think is called every frame).

Third, for your slider, you’re setting the value to a global variable that, from which I can tell, doesn’t exist yet. You should also be using

DNumSlider:OnValueChanged instead of

DNumSlider:ValueChanged because it’s an internal function/feature. Take at the DNumSlider code if you’re having trouble updating the text.

If i create the panel outside the function it will popup, and there goes my isVisible verification

edit: if i only create the label then i get a failed attempt to index upvalue “frame” ( a nil value )