Saving settings
Add one option to a control and it remembers itself between sessions.
One option#
Give any stateful control a Save key and Ember writes it to disk and reads it
back the next time your script runs:
main:Toggle({
Text = "God mode",
Save = "godmode",
Callback = function(on) godmode = on end,
})That is the whole feature. No file paths, no serialisation, no load step.
Restored values do not fire your callback
The switch comes back on, but your script does not know it. Add
FireOnStart = true to any saved control whose callback has a side effect:
main:Toggle({
Text = "Fullbright",
Save = "fullbright",
FireOnStart = true,
Callback = setFullbright,
})What can be saved#
Every control that holds a value: Toggle, Slider, Input, Dropdown,
Keybind, ColorPicker and Palette. Buttons, titles and separators have no
value, so Save does nothing on them.
Keys are yours to choose. They only have to be unique within your script:
main:Slider({ Text = "Speed", Min = 16, Max = 250, Save = "speed" })
main:Dropdown({ Text = "Theme", Options = Ember.ThemeNames(), Save = "theme" })
main:ColorPicker({ Text = "ESP", Save = "espColour" })Where it goes#
By default, a folder called ember in your executor's workspace, in a file
called settings. Change either with Ember.Configure:
Ember.Configure({
Storage = {
Folder = "myscript", -- workspace/myscript/
File = "config", -- workspace/myscript/config.json
},
})Call Configure before Ember.new, so the first window already knows
where to look.
| Option | Type | Default | What it does |
|---|---|---|---|
Enabled | boolean | true | Set false to disable all disk writes, whatever individual controls ask for. |
Folder | string | "ember" | Folder under the executor's workspace. |
File | string | "settings" | File name inside that folder. |
Debounce | number | 0.4 | Seconds to wait before writing. Stops a dragged slider writing every frame. |
Unique | boolean | false | Claim the folder, suffixing _2, _3 if another script already owns it. |
Owner | string | — | Identity for that claim. Defaults to the folder name. |
Two scripts, one folder#
If you publish more than one script, give each its own folder — otherwise the second one loads the first one's settings:
Ember.Configure({
Storage = { Folder = "bloxburg-helper", Owner = "bloxburg-helper" },
})Unique = true goes further: if another script already claimed that folder,
yours quietly becomes bloxburg-helper_2 instead of fighting over it.
Writes are debounced#
Dragging a saved slider does not write to disk on every frame. Writes are collected and flushed 0.4 seconds after the last change, which is why saving is safe to put on a slider at all. Raise it if you are writing a lot:
Ember.Configure({ Storage = { Debounce = 1.0 } })When there is no filesystem#
Saving needs writefile, readfile and isfolder. If the executor does not
provide them, Ember detects that and carries on without persistence — your
window still works, controls still fire, nothing errors. Only the remembering
is lost.
To turn saving off:
Ember.Configure({ Storage = { Enabled = false } })Reading and writing directly#
For state that is not a control — a list of favourites, a session counter —
Ember.Store is the same storage:
Ember.Store.set("favourites", { "Kitchen", "Attic" })
local favourites = Ember.Store.get("favourites") --> table
Ember.Store.clear("favourites")Values must be JSON-encodable: strings, numbers, booleans, and tables of those.