# Function: addOnExportGameState() (/pixi-vn/index/namespaces/Game/functions/addOnExportGameState)



\> **addOnExportGameState**(`handler`): () => `void`

Defined in: [src/index.ts:289](https://github.com/DRincs-Productions/pixi-vn/blob/f55707110b4a4bd56fb1c8547285a9aea26fda31/src/index.ts#L289)

Register a handler that runs every time [exportGameState](/pixi-vn/index/namespaces/Game/functions/exportGameState) is called. It receives the
complete save-state object and can mutate it (add or update properties) before it is
returned. Handlers may be async; they are awaited sequentially in registration order, and
an error thrown by a handler is propagated to the [exportGameState](/pixi-vn/index/namespaces/Game/functions/exportGameState) caller.

Combine it with TypeScript module augmentation of the `GameState` interface to type
the custom properties.

## Parameters [#parameters]

### handler [#handler]

[`OnExportGameStateHandler`](/pixi-vn/index/type-aliases/OnExportGameStateHandler)

The handler to register.

## Returns [#returns]

A function that removes the handler (same as [removeOnExportGameState](/pixi-vn/index/namespaces/Game/functions/removeOnExportGameState)).

() => `void`

## Example [#example]

```ts
declare module "@drincs/pixi-vn" {
    interface GameState {
        myLibraryData?: { score: number };
    }
}

Game.addOnExportGameState(async (state) => {
    state.myLibraryData = { score: await getScore() };
});
```
