aego/settings
Get* return the effective value. Set* only stage a value; Apply makes every staged value take effect at once and Revert drops them. Override* change a value for this session only and are never saved. Scripts with OnSettingChanged(id string) hear about every change. The documentation sandbox does not load the Settings module, so this example needs a project. See Settings.
Example
package demo
import (
"aego/log"
"aego/settings"
)
script Shaker {
@export var Strength float = 1
var frames int
func Ready() {
log.Info("screen shake " + string(settings.GetFloat("accessibility.screenShake")) + ", reduced motion " + string(settings.GetBool("accessibility.reducedMotion")))
settings.OverrideFloat("accessibility.screenShake", 0.25)
}
func Update(dt float) {
frames++
if frames == 30 {
shake := Strength * settings.GetFloat("accessibility.screenShake")
log.Info("shaking with " + string(shake))
settings.ClearOverride("accessibility.screenShake")
}
}
func OnSettingChanged(id string) {
log.Info(id + " is now " + string(settings.GetFloat(id)))
}
}
Functions
| Apply | () bool | Applies every staged value at once; if one fails, none change. |
| ClearOverride | (id string) | Removes a session override. |
| ClearOverrides | () | Removes every session override. |
| CloseView | () | Hides the settings screen. |
| GetBool | (id string) bool | Returns the effective value of an on/off setting. |
| GetFloat | (id string) float | Returns the effective value of a number setting. |
| GetInt | (id string) int | Returns the effective value of an integer or choice setting. |
| GetString | (id string) string | Returns a text setting, or the name of the current choice. |
| NeedsRestart | () bool | Reports whether an applied setting takes effect only after a restart. |
| OpenView | () | Shows the settings screen and pauses the game until it closes. |
| OverrideBool | (id string, value bool) | Sets an on/off value for this session only. |
| OverrideFloat | (id string, value float) | Sets a value for this session only; it is never saved. |
| OverrideInt | (id string, value int) | Sets an integer for this session only. |
| OverrideString | (id string, value string) | Sets a text value for this session only. |
| Reset | (id string) | Stages a return to the project default. |
| Revert | () | Drops the staged values. |
| Save | () | Writes the player profile now; it is also saved on its own shortly after a change. |
| SetBool | (id string, value bool) | Stages a value; Apply makes it take effect. |
| SetFloat | (id string, value float) | Stages a number. |
| SetInt | (id string, value int) | Stages an integer or choice index. |
| SetString | (id string, value string) | Stages a text value. |
| ViewOpen | () bool | Reports whether the settings screen is shown. |
Apply function
func Apply() bool
Applies every staged value at once; if one fails, none change.
Example
if !settings.Apply() {
ClearOverride function
func ClearOverride(id string)
Removes a session override.
Example
settings.ClearOverride("audio.bus.music.volume")
ClearOverrides function
func ClearOverrides()
Removes every session override.
Example
settings.ClearOverrides()
CloseView function
func CloseView()
Hides the settings screen.
Example
settings.CloseView()
GetBool function
func GetBool(id string) bool
Returns the effective value of an on/off setting.
Example
if settings.GetBool("accessibility.reducedMotion") {
GetFloat function
func GetFloat(id string) float
Returns the effective value of a number setting.
Example
shake *= settings.GetFloat("accessibility.screenShake")
GetInt function
func GetInt(id string) int
Returns the effective value of an integer or choice setting.
Example
fps := settings.GetInt("display.frameLimit")
GetString function
func GetString(id string) string
Returns a text setting, or the name of the current choice.
Example
mode := settings.GetString("display.window.mode")
NeedsRestart function
func NeedsRestart() bool
Reports whether an applied setting takes effect only after a restart.
Example
if settings.NeedsRestart() {
OpenView function
func OpenView()
Shows the settings screen and pauses the game until it closes.
Example
settings.OpenView()
OverrideBool function
func OverrideBool(id string, value bool)
Sets an on/off value for this session only.
Example
settings.OverrideBool("audio.bus.sfx.mute", true)
OverrideFloat function
func OverrideFloat(id string, value float)
Sets a value for this session only; it is never saved.
Example
settings.OverrideFloat("audio.bus.music.volume", 0.2)
OverrideInt function
func OverrideInt(id string, value int)
Sets an integer for this session only.
Example
settings.OverrideInt("display.frameLimit", 30)
OverrideString function
func OverrideString(id string, value string)
Sets a text value for this session only.
Example
settings.OverrideString("display.window.resolution", "1280x720")
Reset function
func Reset(id string)
Stages a return to the project default.
Example
settings.Reset("input.sensitivity")
Revert function
func Revert()
Drops the staged values.
Example
settings.Revert()
Save function
func Save()
Writes the player profile now; it is also saved on its own shortly after a change.
Example
settings.Save()
SetBool function
func SetBool(id string, value bool)
Stages a value; Apply makes it take effect.
Example
settings.SetBool("accessibility.subtitles", true)
SetFloat function
func SetFloat(id string, value float)
Stages a number.
Example
settings.SetFloat("audio.bus.music.volume", 0.5)
SetInt function
func SetInt(id string, value int)
Stages an integer or choice index.
Example
settings.SetInt("display.frameLimit", 60)
SetString function
func SetString(id string, value string)
Stages a text value.
Example
settings.SetString("display.window.resolution", "1920x1080")
ViewOpen function
func ViewOpen() bool
Reports whether the settings screen is shown.
Example
if settings.ViewOpen() {