Skip to main content

Player manager

The manager rules over the player state and his synchronization with the server. After SDK initialization, there starts the process of player’s synchronization with the server. Upon completion, the ready event will be called.

Overview

Player manager properties FREE:

// The player is logged in
ss.player.isLoggedIn;
// The player uses one of the login methods (authorization, secret code)
ss.player.hasAnyCredentials;
// Player waiting promise
ss.player.ready;

The player is initialized automatically; you can wait for readiness:

await ss.player.ready;
// The player is ready

// The player is ready
ss.player.on('ready', () => {});

Synchronization

+1 Request

After player model changes, they can be sent to the server and saved locally on the device. It is recommended to sync the player after completing a level and receiving rewards, as well as immediately after an important action, for example, purchasing an item.

// Synchronize, returns the promise
ss.player.sync();
// Overwrite the character on the server (local in priority)
ss.player.sync({ override: true });

// The player is synchronized (success === true)
ss.player.on('sync', (success) => {});
tip

Storage limit: no more than 1 MB per player.

Loading

+1 Request

You can load the player by force from the server (by overwriting the local one).

// Load, returns the promise
ss.player.load();

// The player is loaded (success === true)
ss.player.on('load', (success) => {});

Login

+0-1 Request

Show the overlay with login options. This is currently the platform login (if it is supported) and login by secret code.

// Login, returns the promise
ss.player.login();

// The player is logged in (success === true)
ss.player.on('login', (success) => {});

Logout

+0-1 Request

Logout player. If supported logout on platform.

// Logout, returns the promise
ss.player.logout();

// The player is logged in (success === true)
ss.player.on('logout', (success) => {});

Fetching the fields

+1 Request

See below what player fields are.
You can fetch the player fields using the following method:

// Fetch fields list, returns the promise
ss.player.fetchFields();

// Fields are fetched (success === true)
ss.player.on('fetchFields', (success) => {});

Notification of other windows

FREE

If the player opens another window with the game at the same time as the other open windows of the game - all other windows will receive event:connect. You can subscribe to it like this:

// will be triggered when the player opens another window with the game
ss.on('event:connect', () => {});

Stay in Touch

Other documents of this chapter available Here. To get started, welcome to the Tutorials chapter.

SpellSync Community Telegram: @spellsync.

For your suggestions e-mail: [email protected]

We Wish you Success!