Register Save Handler

Signature

bool registerSaveHandler(string id, function callback)

Description

Registers a save handler for a specific identifier that stores additional information for a save game.

Each identifier is saved as a separate JSON file ({id}.json}) and stored in a directory named after the save game (e.g. FFXII_000.dir).

Returns whether the operation was successful (true) or not (false).

Arguments

Identifier

The unique identifier of the save data.

Callback

The Callback function that is executed when save data is saved.

Example File Structure

saves/
β”œβ”€β”€ FFXII_000.dir/
β”‚   β”œβ”€β”€ mymod-stats.json
β”‚   β”œβ”€β”€ mymod-inventory.json
β”‚   β”œβ”€β”€ mymod-settings.json
β”œβ”€β”€ FFXII_000

Notes

When a save is loaded, all associated loader save data will be loaded as well. When a new save is created, the Lua loader will copy over the existing data from the last loaded save to ensure no data is lost. However, this only applies to data without a save handler or if the existing handler fails.

If a save handler is already registered for an identifier within the same script, registering it again will update the callback instead of adding a new one.

Last updated