Player manager
Overview
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.
Player manager properties:
// The player is logged in
gp.player.isLoggedIn
// The player uses one of the login methods (cookie, authorization, secret code)
gp.player.hasAnyCredentials
// Player waiting promise
gp.player.ready
The player is initialized automatically; you can wait for readiness:
await gp.player.ready;
// The player is ready
// The player is ready
gp.player.on('ready', () => {});
Synchronization
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
gp.player.sync();
// Overwrite the character on the server (local in priority)
gp.player.sync({ override: true });
// The player is synchronized (success === true)
gp.player.on('sync', (success) => {});
Storage limit: no more than 1 MB
per player.
Loading
You can load the player by force from the server (by overwriting the local one).
// Load, returns the promise
gp.player.load();
// The player is loaded (success === true)
gp.player.on('load', (success) => {});
Login
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
gp.player.login();
// The player is logged in (success === true)
gp.player.on('login', (success) => {});
Fetching the fields
See below what player fields are.
You can fetch the player fields using the following method:
// Fetch fields list, returns the promise
gp.player.fetchFields();
// Fields are fetched (success === true)
gp.player.on('fetchFields', (success) => {});
Notification of other windows
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
gp.on('event:connect', () => {})
Stay in Touch
Other documents of this chapter available Here. To get started, welcome to the Tutorials chapter.
GamePush Community Telegram
: @gs_community.
For your suggestions e-mail
: [email protected]
We Wish you Success!