CVARINFO

From ZDoom Wiki
Jump to navigation Jump to search

CVARINFO is a lump for defining custom, mod-specific CVARs. The syntax is as follows:

<scope> [noarchive] [cheat] [latch] [handlerclass("<classname>")] <type> <name> [= defaultvalue];

Scope

This can be one of the following:

  • server
This CVAR is shared by all players, and in network games, only select players can change it. Changes to server CVARs will not be reflected until at-least one tic later (network games will make this length of time indeterminate). Their values are saved to savegame. In ZScript server CVARs are readable directly, like global variables.
  • user
This CVar is not saved to save games, but is written into config (changing this CVar, then loading an earlier save will not modify its value). Each player has their own copy of this CVAR, which they can change independently. Changes to these variables are immediate.
User CVars can be used to store per-player data that should still be visible to all players in multiplayer. For example, player's skin, gender, color and such are stored in user CVars.
Nothing that can modify the playsim (such as spawning actors) should be tied to user CVars, because doing so will cause a desync in multiplayer.
User CVars can be retrieved with CVar.GetCvar('<cvarname>', <PlayerInfo pointer>).
  • nosave
Similarly to user CVars, nosave CVARs are only saved in config files, and each player has their own copy of this CVar. However, they're also not shared across network, so other players don't have access to each other values for this CVar.
Nosave CVars should be used to store user-specific options that are not relevant to other players. For example, options that can modify some UI aspects (such as elements of a custom ZScript HUD) can be tied to a nosave CVar.
Nothing that can modify the playsim (such as spawning actors) should be tied to nosave CVars, because doing so will cause a desync in multiplayer.
In contrast to user CVars, nosave CVars can be safely retrieved with CVar.FindCVar('<cvarname>'), because this function always retrieves the CVar for the consoleplayer, and nosave CVars are not shared across network.

Summarized:

server user nosave
Stored in save games Yes No No
Who can modify in multiplayer Only host Anyone Anyone
Can value be different for each player? No Yes Yes
Shared across network Yes Yes No
How to read in ZScript Readable directly by name,
like a global variable.
CVar.GetCvar('<cvarname>', <PlayerInfo pointer>)

This retrieves a pointer to the CVar. To get the actual value,
use GetInt(), GetFloat(), GetBool(), GetString().
CVar.FindCVar('<cvarname>')

This retrieves a pointer to the CVar. To get the actual value,
use GetInt(), GetFloat(), GetBool(), GetString().
Note, CVar.GetCVar can be used as well, although isn't necessary.
Intended use Data that affects gameplay Data unique to users that doesn't affect gameplay but must be visible to other users. Local user options that aren't relevant to other users.
Note: Server CVAR names must be no longer than 63 characters. While GZDoom 3.4 will refuse to load, prior versions will suffer issues with multiplayer.


Other options

  • noarchive: If present, it prevents the CVAR from being written to the configuration file.
  • cheat: If present, the CVAR can only be modified by console if sv_cheats is enabled. ACS can still change these freely.
  • latch: Changes to this CVAR only take effect upon starting a new game. This is only the case when changing it from the console, however.
  • handlerclass: See Handlers for more information. (New from 4.11.0)
  • type: The data type of the CVAR's value, which can be one of the following:
    • int — An integer value. Defaults to 0.
    • float — A value that can include a fraction. Defaults to 0.0.
    • color — A color value. Defaults to black ("00 00 00").
    • bool — A boolean value that can hold either true or false. Defaults to false.
    • string — A string value. It is not too useful for mods but is included for completeness. Defaults to "".
  • name: The CVAR's name. It must begin with a letter and may only include alphanumeric characters and the underscore character.
Error.gif
Warning: User CVAR name and its value cannot contain more than 254 characters in total. It may be saved to the external configuration file without warning, but the engine will refuse to load it next parsing. Error description will not contain the CVar name.


  • defaultvalue: The default value to be given to the CVAR, if desired.

Example

This creates an integer CVAR with the name mymod_coolness. The CVAR is shared by all players. It has a default value of 10, and it is saved in the configuration file.

server int mymod_coolness = 10;

See also