# 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 %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://xeavin.gitbook.io/ff12-lua-loader/events/functions/register-save-handler.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
