wolfhacklua API 1.1 Forum

store

A small persistent key/value store for the script's settings. Controls made with an id keep their value here.

since 1.0no permission needed

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): any

Reads a value.

ParameterTypeDescription
keystringThe key.
default optionalanyReturned when the key is not stored. default nil
ReturnsDescription
anyThe stored value, or default.
lua
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.

ParameterTypeDescription
keystringA non-empty key.
valueanyA boolean, number, string or table of those. nil deletes the key.
lua
store.set("runs", store.get("runs", 0) + 1)

store.keys#since 1.0

store.keys(): string[]

Lists the keys.

ReturnsDescription
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.

API 1.1 · source docs-src/api/store.json