Skip to main content

Persistence

The Persistence module provides a way to save and load game states, both using a local and remote storage, ensuring a seamless experience for players across sessions.

info

It's up to the developer to decide which storage type to use, between Local and Remote.

Setup

To utilize the Persistence module, initialize the SDK and access the persistence component:

import * as ArkadiumApi from '@arkadiuminc/sdk';

const sdk = await ArkadiumApi.getInstance();

sdk.persistence;

Ensure proper initialization to enable saving and loading functionalities.

Local Storage

Loading Item

To load an item from local storage:

const item = await sdk.persistence.getLocalStorageItem("saved-game-123");

Saving Item

To save an item to local storage:

await sdk.persistence.setLocalStorageItem("saved-game-123", item);

Removing Item

To remove an item from local storage:

await sdk.persistence.removeLocalStorageItem("saved-game-123");

Remote Storage

info

In order to use the Remote Storage APIs, the user needs to be authenticated, meaning that it's a good practice for the game to call the Check Authorization API before using the Remote Storage. Otherwise, if any of the methods below are used without the user being authenticated, an exception will be thrown back to the game.

Use non-circular references when saving items on the remote storage, with a limit of 32KB per value. Focus on saving only essential progression details to maintain performance and prevent issues with large or complex data.

Loading Item

To load an item from remote storage:

const item = await sdk.persistence.getRemoteStorageItem("saved-game-123");

Saving Item

To save an item to remote storage:

await sdk.persistence.setRemoteStorageItem("saved-game-123", item);

Removing Item

To remove an item from remote storage:

await sdk.persistence.removeRemoteStorageItem("saved-game-123");

Cookies

Fetch cookie from arena

const cookie = await sdk.persistence.getCookie('cookie_name');

Conclusion

The Persistence module is crucial for enhancing player engagement by allowing them to store players' game state and persist them between game sessions.