GetCVar (ACS)

From ZDoom Wiki
(Redirected from GetCVar)
Jump to navigation Jump to search

(This is for the ACS function. For the DECORATE function please click here; for the ZScript function please click here.)


Error.gif
Warning: This feature has at least one use case where the outcome is indeterminate. This feature can break demo and multiplayer sync if an indeterminate result is used to modify the playsim (anything that uses the random number generator, modify level geometry, spawn obstacles, monsters, or powerups, and so on). Usage of the feature in conjunction with non-playsim related features, such as displaying a HudMessage, is safe.

Using non-playsim CVARs such as screenblocks or invertmouse will cause indeterminate behavior. Using Server or User variables, either internal or defined via CVARINFO, is however perfectly safe.

int GetCVar (str cvar)

Usage

Returns the value of a particular cvar.

Parameters

Return value

The value of the specified console variable. This is only useful for cvars that can be represented as integers. Also note that you can create your own console variables by using the CVARINFO lump.

If the console variable is a user CVAR, it will check the activator of the script. To check the user CVAR of a specific player, you can use GetUserCVar.

If no such console variable exists, it will return 0.

Examples

This script will spawn Imps only if sv_nomonsters is false:

if (!GetCVar ("sv_nomonsters"))
{
    SpawnSpot ("DoomImp", 66);
    SpawnSpot ("TeleportFog", 66);
}

One possible use for this is if you are making additions to the HUD, you can check if the player is using the status bar or not and act accordingly:

int screenblocks = GetCVar ("screenblocks");

if (screenblocks < 10)
{
    // The status bar is visible
}
else if (screenblocks == 10)
{
    // The fullscreen HUD is visible instead
}
else
{
    // No HUD of any sort is visible
}

See also

Console variable functions
GetCVar SetCVar
GetCVarString SetCVarString
GetUserCVar SetUserCVar
GetUserCVarString SetUserCVarString
CVARINFO