Pixi’VN
indexNamespacesGameFunctions

Function: addOnExportGameState()

pixi-vn on GitHub

> addOnExportGameState(handler): () => void

Defined in: src/index.ts:289

Register a handler that runs every time 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 caller.

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

Parameters

handler

OnExportGameStateHandler

The handler to register.

Returns

A function that removes the handler (same as removeOnExportGameState).

() => void

Example

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

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

On this page