Panel/SetConVar

From Garry's Mod
(Difference between revisions)
Jump to: navigation, search
m (Added warning about serverside cvars on clientside)
(sv_cheats can not be edited like this (blocked cvar). Added note about blocked concommands)
 
Line 2: Line 2:
 
|Description={{Warning|This function does not exist on all panels}}
 
|Description={{Warning|This function does not exist on all panels}}
 
{{Warning|This function cannot interact with serverside convars unless you are host}}
 
{{Warning|This function cannot interact with serverside convars unless you are host}}
 +
{{Note|Blocked convars will not work with this, see [[Blocked ConCommands]]}}
  
 
Sets this panel's convar. When the convar changes this panel will update automatically.
 
Sets this panel's convar. When the convar changes this panel will update automatically.
Line 15: Line 16:
 
}}
 
}}
 
{{Example
 
{{Example
|Description=Makes a checkbox linked to the '''sv_cheats''' convar.
+
|Description=Makes a checkbox linked to the '''cl_drawhud''' convar.
|Code=local checkbox = vgui.Create( "DCheckBoxLabel", myFrame )
+
|Code=local DermaPanel = vgui.Create( "DFrame" )
checkbox:SetConVar( "sv_cheats" )
+
DermaPanel:SetPos( 100, 100 )
checkbox:SetText( "Enable cheats?" )
+
DermaPanel:SetSize( 300, 200 )
checkbox:SetPos( 5, 25 )
+
DermaPanel:SetTitle( "My new Derma frame" )
checkbox:SizeToContents()
+
DermaPanel:SetDraggable( true )
|Output=A checkbox which adapts to the value of the '''sv_cheats''' convar value.
+
DermaPanel:MakePopup()
  
[[File:checkbox_SetConVar.jpg]]
+
local Checkbox = vgui.Create( "DCheckBoxLabel", DermaPanel )
 +
Checkbox:SetConVar( "cl_drawhud" )
 +
Checkbox:SetText( "Enable HUD?" )
 +
Checkbox:SetPos( 5, 25 )
 +
Checkbox:SizeToContents()
 +
|Output=[[File:panel_setcvar.png]]
 
}}
 
}}

Latest revision as of 11:49, 12 October 2019

 Panel:SetConVar( )

Contents

Description

WARNING

This function does not exist on all panels

WARNING

This function cannot interact with serverside convars unless you are host

NOTE

Blocked convars will not work with this, see Blocked ConCommands

Sets this panel's convar. When the convar changes this panel will update automatically.

For developer implementation, see Derma_Install_Convar_Functions.

Arguments

string convar

The console variable to check.

Examples

Example

Makes a checkbox linked to the cl_drawhud convar.

local DermaPanel = vgui.Create( "DFrame" )
DermaPanel:SetPos( 100, 100 )
DermaPanel:SetSize( 300, 200 )
DermaPanel:SetTitle( "My new Derma frame" )
DermaPanel:SetDraggable( true )
DermaPanel:MakePopup()

local Checkbox = vgui.Create( "DCheckBoxLabel", DermaPanel )
Checkbox:SetConVar( "cl_drawhud" )
Checkbox:SetText( "Enable HUD?" )
Checkbox:SetPos( 5, 25 )
Checkbox:SizeToContents()

Output:

panel setcvar.png
Personal tools
Navigation