PlayerData - pogamesdk/POGAME-Cocos GitHub Wiki

Player data

You can save game state data (completed levels, experience, in-game purchases and such). To work with user data, use the Player object.

To initialize the Player object, use the posdk.getPlayer() method.

var player;

posdk.getPlayer().then(_player => {
        player = _player;
    }).catch(err => {
        // Error initializing the Player object.
    });

To work with the user's in-game data, use the Player object methods:

  • player.saveData(data): Saves the user data. The maximum data size must not exceed 200 KB.

    • data: Object, an object containing key-value pairs.

    The method returns a Promise that indicates whether the data was saved or not.

player.saveData({
        achievements: ['trophy1', 'trophy2', 'trophy3'],
    }).then(() => {
        console.log('data is set');
    }).catch(err => {
        // Error save the Player Data.
    });
  • player.getData(keys): Asynchronously returns in-game user data stored in the POGAME database.

    • keys: Array, the list of keys to return. If the keys parameter is missing, the method returns all in-game user data.

    The method returns Promise<Object>, where the object contains key-value pairs.

player.getData(['key1', 'key2', 'key3'])
    .then(result => {
        console.log(result)
    }).catch(err => {
        // Error get the Player Data.
    });
⚠️ **GitHub.com Fallback** ⚠️