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:
- JavaScript
- Unity
// The player is logged in
gp.player.isLoggedIn;
// The player uses one of the login methods (authorization, secret code)
gp.player.hasAnyCredentials;
// Player waiting promise
gp.player.ready;
// The player is logged in
GP_Player.IsLoggedIn();
// The player uses one of the login methods (cookie, authorization, secret code)
GP_Player.HasAnyCredentials();
The player is initialized automatically; you can wait for readiness:
- JavaScript
- Unity
await gp.player.ready;
// The player is ready
// The player is ready
gp.player.on('ready', () => {});
Initialization in Unity occurs before the game starts
Synchronization
+0-1 RequestAfter making changes in the player, you can send them to the server and save locally on the device. It is recommended to synchronize the player after completing a level and receiving rewards, as well as immediately after important actions, such as purchasing an item.
- JavaScript
- Unity
// Sync, returns a promise
gp.player.sync();
// Overwrite the character on the server (local takes priority)
gp.player.sync({ override: true });
// Sync data with the selected storage
// "preferred" - specified storage in the control panel
// "cloud" - our cloud + platform's cloud + local storages
// "platform" - platform's cloud + local storages
// "local" - local storages
gp.player.sync({ storage: 'preferred' });
// Player synchronized (success === true)
gp.player.on('sync', (success) => {});
// Sync the player
GP_Player.Sync();
// Overwrite the character on the server (local takes priority)
GP_Player.Sync(forceOverride: true);
// Sync data with the selected storage
// "preferred" - specified storage in the control panel
// "cloud" - GamePush's cloud. At the time of saving, data is also replicated in the platform's cloud and local storages for maximum reliability.
// "platform" - platform's cloud.
GP_Player.Sync(storage: SyncStorageType.preferred);
Limitation on saved data: no more than 1 MB
per player.
Synchronize with Selected Storage
You can save progress both in the GamePush cloud and locally and in the platform's cloud.
Storage types:
preferred +0-1 Request - Preferred storage, determined in the control panel.
cloud +1 Request - GamePush's cloud. At the time of saving we also replicate data in the platform's cloud and local storages for maximum reliability.
platform FREE - Platform's cloud.
- ✅Yandex Games
- ✅CrazyGames
Platforms without support
- ❌GamePix
- ❌GameDistribution
- ❌GameMonetize
- ❌OK Games
- ❌SmartMarket
- ❌VK Games
- ❌VK Play
- ❌WG Playground
- ❌Kongregate
- ❌PlayDeck
- ❌Google Play
- ❌Telegram
- ❌beeline
- ❌Fotostrana
- ❌Y8
- ❌CoolMathGames
- ❌Android (alternative stores)
- ❌Web (custom site)
local FREE - Local storages, parallel saving in multiple types of local storages for reliability without losing progress on iOS.
- LocalStorage - standard local storage.
- IndexedDB - browser database.
- SafeStorage - safe storage provided by the platform.
- ✅Yandex Games
- ✅GamePix
- ✅CrazyGames
- ✅Web (custom site)
Platforms without support
- ❌GameDistribution
- ❌GameMonetize
- ❌OK Games
- ❌SmartMarket
- ❌VK Games
- ❌VK Play
- ❌WG Playground
- ❌Kongregate
- ❌PlayDeck
- ❌Google Play
- ❌Telegram
- ❌beeline
- ❌Fotostrana
- ❌Y8
- ❌CoolMathGames
- ❌Android (alternative stores)
There are 2 options to implement saving in the desired storage:
- Set the storage in the control panel for the platform. In this case, when synchronizing normally, all data will be saved in the storage specified in the control panel.
- Specify the data storage during synchronization in the code:
- JavaScript
- Unity
// By default, synchronize with the storage specified in the control panel
gp.player.sync({ storage: 'preferred' });
// Sync with GamePush cloud
gp.player.sync({ storage: 'cloud' });
// Sync with platform's cloud
gp.player.sync({ storage: 'platform' });
// Sync with local storage
gp.player.sync({ storage: 'local' });
// By default, synchronize with the storage specified in the control panel
GP_Player.Sync(SyncStorageType.preferred);
// Sync with GamePush cloud
GP_Player.Sync(SyncStorageType.cloud);
// Sync with platform's cloud
GP_Player.Sync(SyncStorageType.platform);
// Sync with local storage
GP_Player.Sync(SyncStorageType.local);
Automatic Synchronization
To simplify synchronization control, you can enable automatic synchronization in the required storages. Data will be saved only if player fields have been changed.
- JavaScript
- Unity
// Enable synchronization
gp.player.enableAutoSync({
// synchronization frequency in seconds
interval: 30,
// By default, synchronize with the storage specified in the control panel
storage: 'preferred',
});
// Disable synchronization
gp.player.disableAutoSync({ storage: 'preferred' });
// Examples:
// Enable synchronization with local storage every 5 seconds
gp.player.enableAutoSync({
interval: 5,
storage: 'local',
});
// Sync with GamePush cloud every 30 seconds
gp.player.enableAutoSync({
interval: 30,
storage: 'cloud',
});
// Enable synchronization
GP_Player.EnableAutoSync(
// synchronization frequency in seconds
interval: 30,
// By default, synchronize with the storage specified in the control panel
storage: SyncStorageType.preferred
);
// Disable synchronization
GP_Player.DisableAutoSync(storage: SyncStorageType.preferred);
// Examples:
// Enable synchronization in local storage every 5 seconds
GP_Player.EnableAutoSync(
interval: 5,
storage: SyncStorageType.local,
);
// Sync with GamePush cloud every 30 seconds
GP_Player.EnableAutoSync(
interval: 30,
storage: SyncStorageType.cloud
);
Additional Synchronization of Public Fields in the Cloud
In cases where you are satisfied with local storage or the platform's cloud, but you have social mechanics, such as leaderboards, you can additionally check "When synchronizing, save public fields to the cloud" in the platform settings.
This way, you can continue to save to the preferred storage and once you update a public field, it will be saved in our cloud on the next synchronization method call. Save to cloud storage will not occur until a public field is changed.
Loading
+1 RequestYou can load the player by force from the server (by overwriting the local one).
- JavaScript
- Unity
// Load, returns the promise
gp.player.load();
// The player is loaded (success === true)
gp.player.on('load', (success) => {});
// Load player
GP_Player.Load();
Login
+0-1 RequestShow the overlay with login options. This is currently the platform login (if it is supported) and login by secret code.
- JavaScript
- Unity
// Login, returns the promise
gp.player.login();
// The player is logged in (success === true)
gp.player.on('login', (success) => {});
// Open login overlay
GP_Player.Login();
// Event subscription
private void OnEnable()
{
GP_Player.OnLoginComplete += OnLoginComplete;
GP_Player.OnLoginError += OnLoginError;
}
// Event unsubscription
private void OnDisable()
{
GP_Player.OnLoginComplete -= OnLoginComplete;
GP_Player.OnLoginError -= OnLoginError;
}
// Event handling
private void OnLoginComplete()
{
Debug.Log("LoginComplete");
}
// Event handling
private void OnLoginError()
{
Debug.Log("LoginError");
}
Logout
+0-1 RequestLogout player. If supported logout on platform.
- JavaScript
- Unity
// Logout, returns the promise
gp.player.logout();
// The player is logged out (success === true)
gp.player.on('logout', (success) => {});
// Logout player
GP_Player.Logout();
// Event subscription
private void OnEnable()
{
GP_Player.OnLogoutComplete += OnLogoutComplete;
GP_Player.OnLogoutError += OnLogoutError;
}
// Event unsubscription
private void OnDisable()
{
GP_Player.OnLogoutComplete -= OnLogoutComplete;
GP_Player.OnLogoutError -= OnLogoutError;
}
// Event handling
private void OnLogoutComplete()
{
Debug.Log("LogoutComplete");
}
// Event handling
private void OnLogoutError()
{
Debug.Log("LogoutError");
}
Fetching the fields
+1 RequestSee below what player fields are.
You can fetch the player fields using the following method:
- JavaScript
- Unity
// Fetch fields list, returns the promise
gp.player.fetchFields();
// Fields are fetched (success === true)
gp.player.on('fetchFields', (success) => {});
// Fetch fields list
private Fetch() => GP_Player.FetchFields(OnFetchFields);
// Fields are fetched
private OnFetchFields(List<PlayerFetchFieldsData> data){
}
Notification of other windows
FREEIf 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:
- JavaScript
- Unity
// will be triggered when the player opens another window with the game
gp.on('event:connect', () => {});
//Subscribe to event
private void OnEnable()
{
GP_Player.OnConnect += OnConnect;
}
//Unsubscribe from event
private void OnDisable()
{
GP_Player.OnConnect -= OnConnect;
}
//On trigger event
private void OnConnect()
{
Debug.Log("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!