store
A small persistent key/value store for the script's settings. Controls made with an id keep their value here.
The store holds booleans, numbers, strings and tables of those (no functions, no cycles). It is limited to 512 KB and is saved to script-data\<id>\settings.json about a second after a change and when the script unloads. A control created with an id, such as ui.toggle("show", ...), reads and writes its value here under that key, so store.get("show", true) returns what the toggle shows. Changing a value fires the settings event.
Reference#
store.get#since 1.0
store.get(key: string, default?: any): anyReads a value.
| Parameter | Type | Description |
|---|---|---|
key | string | The key. |
default optional | any | Returned when the key is not stored. default nil |
| Returns | Description |
|---|---|
any | The stored value, or default. |
local show = store.get("show", true)store.set#since 1.0
store.set(key: string, value: any)Stores a value. A function, a table with a cycle or an empty key is an error.
| Parameter | Type | Description |
|---|---|---|
key | string | A non-empty key. |
value | any | A boolean, number, string or table of those. nil deletes the key. |
store.set("runs", store.get("runs", 0) + 1)store.keys#since 1.0
store.keys(): string[]Lists the keys.
| Returns | Description |
|---|---|
string[] | Every stored key. |
store.save#since 1.0
store.save()Writes the store to disk now instead of waiting. Rarely needed: it is saved on a short delay and at unload.