Garry's Mod Wiki

GetConVar

  ConVar GetConVar( string name )

Description

Gets the ConVar with the specified name.

This function uses GetConVar_Internal internally, but caches the result in Lua for quicker lookups.
Due to this function using GetConVar_Internal internally it tends to be relatively slow. Please attempt to 'cache' the return of what you used to make it instead of using this function.

Example:

local exampleConvar = CreateClientConVar("exampleConvar", "hi") print(exampleConvar:GetString())

Arguments

1 string name
Name of the ConVar to get

Returns

1 ConVar
The ConVar object, or nil if no such ConVar was found.

Example

Makes a ConVar and utilizes GetConVar to print the value of the ConVar.

CreateClientConVar("exampleConvar", "hi") concommand.Add("exampleConvar2", function() MsgN("ConVar Value: " .. GetConVar("exampleConvar"):GetString()) end)
Output:
ConVar Value: hi