CVar (ZScript)

From ZDoom Wiki
Jump to navigation Jump to search
Note: This feature is for ZScript only.


The CVar struct is a container of functions (methods) used to access and manipulate console variables.

Methods

Static

  • CVar FindCVar (Name name)
Searches for the console variable specified by name, returning it if it finds it. If the variable could not be found, the function returns null.
  • CVar GetCVar (Name name, PlayerInfo player = null)
Returns a specific player's user console variable of that name. Not to be confused with the ACS function or the DECORATE expression which return numeric values stored in the named console variable.

Non-static

  • bool GetBool ()
Returns the value of the console variable as a boolean value.
  • double GetFloat ()
Returns the value of the console variable as a floating-point value.
  • int GetInt ()
Returns the value of the console variable as an integer value.
  • int GetRealType ()
Returns the type of the console variable. The types are as follows:
  • CVAR_Bool
  • CVAR_Int
  • CVAR_Float
  • CVAR_String
  • CVAR_Color
  • String GetString ()
Returns the value of the console variable as a string. For color console variables, this is in the form of "RR GG BB", e.g. "00 ff 00" for green.
Note: Engine-defined console variables can only be set or reset from menus.


  • int ResetToDefault ()
Resets the console variable's value to its default value.
  • void SetBool (bool b)
Sets the value of a boolean console variable to the specified value.
  • void SetFloat (double v)
Sets the value of a floating-point console variable to the specified value.
  • void SetInt (int v)
Sets the value of an integer or color console variable to the specified value. For color console variables, this can be done by passing the value as a hexadecimal value, e.g. 0x00ff00 for green.
  • void SetString (String s)
Sets the value of a string or color console variable to the specified string. For color console variables, this can be done by passing the value in the form of "RR GG BB", e.g. "00 ff 00" for green. Color names from the X11R6RGB lump are also accpetable.

Examples

The attack this imp does depends on the value of the specialimpattack custom console variable.

// In CVARINFO:
server int specialimpattack;
// In ZScript:
class ExampleImp : DoomImp
{
    Default
    {
        +DONTHARMCLASS
    }

    void A_SpecialTroopAttack ()
    {
        CVar attacksetting = CVar.FindCVar('specialimpattack');

        if(attacksetting)
        {
            switch(attacksetting.GetInt())
            {
                default:
                case 0: A_TroopAttack(); break;
                case 1: A_BruisAttack(); break;
                case 2: A_CyberAttack(); break;
            }
        }
    }

    States
    {
    Melee:
    Missile:
        TROO EF 8 A_FaceTarget;
        TROO G 6 A_SpecialTroopAttack;
        Goto See;
    }
}