The engine exposes the console as a means for the user to set and store values of console variables, in order to manipulate the state of the game and engine without requiring source code modifications. Additionally, the console allows for console commands, similar to variables but execute a function whenever it is executed by the user.
The console can be manipulated either through code, or by pressing the tilde key in-game.
Often referred to as CVars, console variables can be registered in code in order to expose a global variable that can be tweaked by designers without modifying code later on. CVars are represented by the ICVar interface in code. For an example of how to create a CVar, see IConsole::Register.
Adding a CVar can be done in many ways:
Console variable groups provide a convenient way to apply predefined settings to multiple console variables at once, and are commonly referred to as CVarGroup. The main use case for CVarGroups is for changing the graphical spec, using the "sys_spec" CVar.
Config/CVarGroups
directory.[default]
; default of this CVarGroup
= 4
e_particles_lod=1
e_particles_max_emitter_draw_screen=64
[1]
e_particles_lod=0.75
e_particles_max_emitter_draw_screen=1
[2]
e_particles_max_emitter_draw_screen=4
[3]
e_particles_max_emitter_draw_screen=16
This creates a new console variable group named "sys_spec_Particles" that behaves like an integer console variable. By default, this variable has the state 4 (set through the line following the comment).
On changing the variable, the new state is applied. Console variables not specified in the .cfg file are not set. All desired console variables need to be part of the default section. An error message is output in case of violation of this rule.
If a console variable is not specified in a custom section, the value specified in the default section is applied.
Similarly to Console Variables, Console Commands are referred to as CCommands and provide support for executing a function whenever the specified command is executed. For an example of how to create your own console commands, see IConsole::AddCommand.
This concludes the article on the console. You may be interested in: