> For the complete documentation index, see [llms.txt](https://xeavin.gitbook.io/ff12-lua-loader/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://xeavin.gitbook.io/ff12-lua-loader/events/functions/register-save-handler.md).

# Register Save Handler

### Signature

```csharp
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](/ff12-lua-loader/events/functions/register-save-handler/callback.md) 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

{% hint style="info" %}
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.
{% endhint %}

{% hint style="warning" %}
It is recommended to use a unique, mod-specific prefix for identifiers to avoid collisions with other scripts that may define similar names.
{% endhint %}

{% hint style="warning" %}
The first script to register a save handler for an identifier owns it.

Trying to register a save handler for an identifier owned by another script will throw a warning and then be ignored.
{% endhint %}

{% hint style="info" %}
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.
{% endhint %}
