Storable
⚠️
This page is under construction.
⚠️
Beta feature, subject to change.
Storable allows you to store data in the game's state. Data stored in Storable will be saved and loaded with current game state.
Data stored in Storable are separated by namespace. You can use the same key in different namespaces.
For example, you can store the player1's name in the player1
namespace and the player2's name in the player2
namespace.
Namespace game
is already defined and can store data, you can add your own by instantiating a new Namespace.
For example, create a new namespace player1
and store the player1's name in it:
type Player1Content = {
name: string;
};
const storable = game.getLiveGame().getStorable();
// initialize a new namespace
const player1namespace = new Namespace<Player1Content>();
storable.addNamespace('player1', player1namespace);
// set data from the namespace
const namespace = storable.getNamespace<Player1Content>('player1');
namespace.set('name', 'John Doe');
// get data from the namespace
const name = namespace.get('name');
console.log(name); // John Doe
Public Methods
addNamespace<T extends NameSpaceContent<keyof T>>
namespace: Namespace<T>
return this
getNamespace<T extends NameSpaceContent<keyof T> = any>
key: string
- The namespace keyreturn Namespace<T>
setNamespace<T extends NameSpaceContent<keyof T> = any>
key: string
- The namespace keynamespace: Namespace<T>
return: this
getNamespaces
return: { [key: string]: Namespace<any>; }
keys
return: string[]
values
return: Namespace<any>[]
entries
return: [string, Namespace<any>][]