Enfusion Script API
Loading...
Searching...
No Matches
ModuleGameSettings Interface Reference

By inheriting of this class you define a settings module. More...

Inheritance diagram for ModuleGameSettings:
ScriptAndConfig Managed

Additional Inherited Members

- Public Member Functions inherited from Managed
proto external ref Managed Clone ()
 Return shallow copy of object, or null if it is not allowed (not public constructor)
 

Detailed Description

By inheriting of this class you define a settings module.

// my settings module definition
class MyGameSettings: ModuleGameSettings
{
int speed;
}
// write my settings (ideally in setting menu?)
void ChangeMySettings()
{
// approach #1
GetGame().GetGameUserSettings().GetModule("MyGameSettings").Set("speed", Math.RandomInt(0, 100));
// approach #2
MyGameSettings settings = new MyGameSettings();
settings.speed = Math.RandomInt(0, 100);
BaseContainerTools.ReadFromInstance(settings, GetGame().GetGameUserSettings().GetModule("MyGameSettings"));
// notify system about change
GetGame().UserSettingsChanged(); // -> here is also OnSpeedChanged() called
GetGame().SaveUserSettings(); // this is also call automatically during game exit, call it manually only on very important cases (like leaving settings menu)
}
// register to receive notification about changes
void SomewhereInInit()
{
GetGame().OnUserSettingsChangedInvoker().Insert(OnSpeedChanged);
}
// read my settings
void OnSpeedChanged()
{
// approach #1
int speed;
GetGame().GetGameUserSettings().GetModule("MyGameSettings").Get("speed", speed);
Print("#1 Speed changed = " + speed);
// approach #2
MyGameSettings settings = new MyGameSettings();
BaseContainerTools.WriteToInstance(settings, GetGame().GetGameUserSettings().GetModule("MyGameSettings"));
Print("#2 Speed changed = " + settings.speed);
}
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
Definition attributes.c:259
Definition BaseContainerTools.c:13
static proto void WriteToInstance(notnull Class inst, BaseContainer src)
static proto void ReadFromInstance(notnull Class inst, BaseContainer src)
Definition Math.c:13
static proto int RandomInt(int min, int max)
Returns a random int number between min [inclusive] and max [exclusive].
By inheriting of this class you define a settings module.
Definition gameLib.c:339

The documentation for this interface was generated from the following file: