zscript-doc/api/base/CVar.md

83 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();
}
```
2019-08-14 03:31:41 -07:00
### `FindCVar`
2018-12-29 16:05:19 -08:00
2019-08-14 03:31:41 -07:00
Returns a server CVar by name, or `null` if none is found.
2018-12-29 16:05:19 -08:00
2019-08-14 03:31:41 -07:00
### `GetCVar`
2018-12-29 16:05:19 -08:00
2019-08-14 03:31:41 -07:00
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
2019-08-14 03:31:41 -07:00
### `GetBool`
2018-12-29 16:05:19 -08:00
2019-08-14 03:31:41 -07:00
Returns a boolean representing the value of the CVar, or `false` if it
cannot be represented.
2018-12-29 16:05:19 -08:00
2019-08-14 03:31:41 -07:00
### `GetFloat`
2018-12-29 16:05:19 -08:00
2019-08-14 03:31:41 -07:00
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
2019-08-14 03:31:41 -07:00
### `GetInt`
2018-12-29 16:05:19 -08:00
2019-08-14 03:31:41 -07:00
Returns an integer representing the value of the CVar, or `0` if it cannot be
represented.
2018-12-29 16:05:19 -08:00
2019-08-14 03:31:41 -07:00
### `GetString`
2018-12-29 16:05:19 -08:00
2019-08-14 03:31:41 -07:00
Returns a string representing the value of the CVar. CVars can always be
represented as strings.
2018-12-29 16:05:19 -08:00
2019-08-14 03:31:41 -07:00
### `SetBool`, `SetFloat`, `SetInt`, `SetString`
2018-12-29 16:05:19 -08:00
2019-08-14 03:31:41 -07:00
Sets the representation of the CVar to `v`. May only be used on mod-defined
CVars.
2018-12-29 16:05:19 -08:00
2019-08-14 03:31:41 -07:00
### `GetRealType`
2018-12-29 16:05:19 -08:00
2019-08-14 03:31:41 -07:00
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
2019-08-14 03:31:41 -07:00
| Name |
| ---- |
| `CVar.CVAR_BOOL` |
| `CVar.CVAR_COLOR` |
| `CVar.CVAR_FLOAT` |
| `CVar.CVAR_INT` |
| `CVar.CVAR_STRING` |
2018-12-29 16:05:19 -08:00
2019-08-14 03:31:41 -07:00
### `ResetToDefault`
2018-12-29 16:05:19 -08:00
2019-08-14 03:31:41 -07:00
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 -->