zscript-doc/api/base/CVar.md

86 lines
1.8 KiB
Markdown
Raw Normal View History

2018-12-29 16:05:19 -08:00
# CVar
A **C**onsole **Var**iable, either defined in `CVARINFO` or by the engine.
**Not serializable. Do not use as a member unless marked as `transient`.**
2018-12-29 16:05:19 -08:00
All Get and Set operations will work regardless of the real type of the CVar,
as they aren't "strongly" typed.
2018-12-29 16:05:19 -08:00
```
struct CVar
{
static CVar FindCVar(name n);
static CVar GetCVar(name n, PlayerInfo player = null);
bool GetBool();
double GetFloat();
int GetInt();
string GetString();
void SetBool(bool v);
void SetFloat(double v);
void SetInt(int v);
void SetString(string v);
int GetRealType();
int ResetToDefault();
}
```
- `FindCVar`
Returns a server CVar by name, or `null` if none is found.
- `GetCVar`
Returns a user or server CVar by name, with `player` as the user if
applicable, or `null` if none is found.
2018-12-29 16:05:19 -08:00
- `GetBool`
Returns a boolean representing the value of the CVar, or `false` if it
cannot be represented.
2018-12-29 16:05:19 -08:00
- `GetFloat`
Returns a float representing the value of the CVar, or `0.0` if it cannot be
represented.
2018-12-29 16:05:19 -08:00
- `GetInt`
Returns an integer representing the value of the CVar, or `0` if it cannot
be represented.
2018-12-29 16:05:19 -08:00
- `GetString`
Returns a string representing the value of the CVar. CVars can always be
represented as strings.
2018-12-29 16:05:19 -08:00
- `SetBool`
- `SetFloat`
- `SetInt`
- `SetString`
Sets the representation of the CVar to `v`. May only be used on mod-defined
CVars.
2018-12-29 16:05:19 -08:00
- `GetRealType`
Returns the type of the CVar as it was defined, which may be one of the
following:
2018-12-29 16:05:19 -08:00
| Name |
| ---- |
2019-04-10 06:12:18 -07:00
| `CVar.CVAR_BOOL` |
| `CVar.CVAR_COLOR |
| `CVar.CVAR_FLOAT` |
| `CVar.CVAR_INT` |
| `CVar.CVAR_STRING` |
2018-12-29 16:05:19 -08:00
- `ResetToDefault`
Resets the CVar to its default value and returns 0. The purpose of the
return is unknown. May only be used on mod-defined CVars.
2018-12-29 16:05:19 -08:00
<!-- EOF -->