Skip to content

Global variables

Roman Chistokhodov edited this page Jul 23, 2024 · 5 revisions

Global variables are named variables accessible across multiple levels. This feature existed in original Half-Life and has been extended in Featureful SDK.

In addition to State (which can be On, Off or Dead) each global variable has an associated numeric integer Value.

Just like in original HL, global variables can be set and read via env_global entity. It got some new parameters in Featureful SDK.

env_global

  • New spawnflag Act as Master. See Master entities
  • New Trigger Mode options: Modify/Set value and Set State: Obey Use-type.
  • New parameter Initial Value to set the initial numeric value of the global variable.
  • When used as [LR] parameter it reports the numeric value of the global variable. See Locus system and Math.

Reaction to use-type:

  • Depending on the Trigger Mode it might ignore the input use-type and change the associated global variable state according to the selected trigger mode. Selecting Set State: Obey Use-type makes it obey the use-type.
  • If Trigger Mode is Modify/Set value it reacts as follows:
    • If use-type is Set (e.g. fired by game_counter_set or calc_eval_number) it assigns the input value to the numeric value of the associated global variable.
    • If use-type is Toggle or On it increments the numeric value of the associated global variable by 1.
    • If use-type is Off it decrements the numeric value of the associated global variable by 1.
    • In all cases if the global variable doesn't exist yet, it gets created first with the numeric value from Initial Value.

See also: env_global on twhl wiki

Accessing global variables via console

To see the output of the following commands you must set developer cvar to 1 or higher.

  • impulse 104 is used to output all existing global variables.
  • set_global_state - set a global variable state (off, on, dead). This is for debugging purposes and it's allowed only when sv_cheats is enabled.
  • set_global_value - set a number value associated with a global variable. This is for debugging purposes and it's allowed only when sv_cheats is enabled.
Clone this wiki locally