What is pSelf and fValue ?

I see in Gmod wiki this code but I don’t know what is pSelf and fValue…
and when I write this it give me an error.

[lua] local DermaPanel = vgui.Create( “DFrame” )
local NumSlider = vgui.Create( “DNumSlider”, DermaPanel )
NumSlider:SetPos( 25,50 )
NumSlider:SetWide( 150 )
NumSlider:SetText( “Max Props” )
NumSlider:SetMin( 0 ) – Minimum number of the slider
NumSlider:SetMax( 256 ) – Maximum number of the slider
NumSlider:SetDecimals( 0 ) – Sets a decimal. Zero means it’s a whole number
NumSlider:SetConVar( “sbox_maxprops” ) – Set the convar
NumSlider.ValueChanged = function(pSelf, fValue)
print("Max prop changed to: "…fValue)
end [/lua]

When declaring arguments of a function you can write just about any name you want and it will work. In this case it’s just the names the coder chose for the arguments passed to his function. They could’ve been called cow and potato and it would still work.

As for the error it would help if you posted it. A reason you could be getting one is if you are using that code on the server, which you should not be doing.

For my error, it’s with this code. But the value I want to have is the value of the slider in a label when the value change.

[lua]function startframe() // the frame it will be set in.
local SizeNX = CreateClientConVar( “C_SizeX”, “0”, false, false)
local GetSizeX = SizeNX:GetFloat()

local DermaPanel = vgui.Create( “DFrame” ) – Creates the frame itself
DermaPanel:SetSize( 210, 315 ) – Size of the frame ( use half the width / height of your screen )
DermaPanel:SetPos( 300, 100 )
DermaPanel:SetTitle( “Testing Derma Stuff” ) – Title of the frame
DermaPanel:GetDraggable( )
DermaPanel:GetSizable( )
DermaPanel:SetVisible( true )
DermaPanel:SetDraggable( true ) – Draggable by mouse?
DermaPanel:ShowCloseButton( true ) – Show the close button?
DermaPanel:MakePopup( ) – Show the frame
DermaPanel.Paint = function()
draw.RoundedBox( 2, 0, 0, DermaPanel:GetWide() , DermaPanel:GetTall(), Color( 100, 100, 100, 255 ) ) end

local NumSliderX = vgui.Create( “DNumSlider”, DermaPanel )
NumSliderX:SetPos( 25,50 )
NumSliderX:SetWide( 150 )
NumSliderX:SetText( fValue )
NumSliderX:SetMin( 0 ) – Minimum number of the slider
NumSliderX:SetMax( 512 ) – Maximum number of the slider
NumSliderX:SetDecimals( 0 ) – Sets a decimal. Zero means it’s a whole number
NumSliderX:SetConVar( “C_SizeX” ) – Set the convar

local NumSlider = vgui.Create( “DNumSlider”, DermaPanel )
NumSlider:SetPos( 25,50 )
NumSlider:SetWide( 150 )
NumSlider:SetText( “Max Props” )
NumSlider:SetMin( 0 ) – Minimum number of the slider
NumSlider:SetMax( 256 ) – Maximum number of the slider
NumSlider:SetDecimals( 0 ) – Sets a decimal. Zero means it’s a whole number
NumSlider:SetConVar( “sbox_maxprops” ) – Set the convar
NumSlider.ValueChanged = function(pSelf, fValue)
print("Max prop changed to: "…fValue)
end

end

concommand.Add(“MyTestPanel”,startframe,startframe)[/lua]



autorun\client	est.lua:21: attempt to concatenate global 'fValue' (a nil value)
Running script autorun\client	est.lua...
vgui/DNumSlider.lua:96: bad argument #1 to 'SetText' (string expected, got nil)


Your problem is that fValue only exists inside of the function so you can’t use it anywhere else. What you should do is move NumSliderX:SetText() inside of the function assigned to ValueChanged. That way each time the value changes you can effectively set it to fValue.

You should also set the text to a default string somewhere so there is something to display until the slider changes value.

NumSliderX.Paint = function()
NumSliderX:SetText(NumSlider:GetValue())
end

or

NumSlider.ValueChanged = function(s, val)
NumSliderX:SetText(val)
end

Thanks I’ll give a try in a hour, but in the function can I add what I want ? like function(s, val, test, args1) how I can know what I need to add inside ?

Use the wiki, it will tell you what functions use what arguments.

Cool thanks its working as well with these 2 way :slight_smile:

I see in wiki : Output Self Panel, Panel Value

what mean this ? Self Panel is for my DermaPanel and Panel Value is for the Value of NumSliderX ?

self is the panel itself in this case “NumSlider” , value is the value the slider is at.

so you set the text on NumSliderX to the value of NumSlider