---
metadata:
  - name: generator
    content: Diplodoc Platform v5.66.0
alternate:
  - https://yandex.com/dev/games/doc/en/sdk/defold/player-data.md
  - https://yandex.com/dev/games/doc/hi/sdk/defold/player-data.md
  - https://yandex.com/dev/games/doc/ko/sdk/defold/player-data.md
  - https://yandex.com/dev/games/doc/ru/sdk/defold/player-data.md
  - https://yandex.com/dev/games/doc/tr/sdk/defold/player-data.md
  - https://yandex.com/dev/games/doc/vi/sdk/defold/player-data.md
  - https://yandex.com/dev/games/doc/zh/sdk/defold/player-data.md
  - href: https://yandex.com/dev/games/doc/en/sdk/defold/player-data.md
    type: text/markdown
    title: Markdown version
  - href: https://yandex.com/dev/games/doc/en/llms.txt?revision=r21993288
    rel: describedby
---
> **Documentation Index:** Fetch the complete configuration index at https://yandex.com/dev/games/doc/en/llms.txt?revision=r21993288

# Player data

<!-- source: en/_includes/script-common.md -->
<!-- source: en/_includes/script/index-js.md -->

<!-- endsource: en/_includes/script/index-js.md -->

<!-- source: en/_includes/script/requirements-js.md -->

<!-- endsource: en/_includes/script/requirements-js.md -->

<!-- source: en/_includes/script/image-modal-js.md -->

<!-- endsource: en/_includes/script/image-modal-js.md -->
<!-- endsource: en/_includes/script-common.md -->

<!-- source: en/_includes/sdk/common-with-plugins.md -->
You can:

- Save game data (completed levels, experience, in-app purchases, etc.) on the Yandex server using SDK methods or transfer it to your own server. Cloud saves allow users to continue playing on different devices.
- Personalize the game using data from the user's Yandex profile, such as their name.
<!-- endsource: en/_includes/sdk/common-with-plugins.md -->

## Player Information {#player-info}

```lua showLineNumbers
ysdk.player.get_info(
    callback: function,
    options: {
        scopes: boolean|nil,
        signed: boolean|nil
    }
)
```

`callback: function` — callback of the called method. Has the following form:

```lua
function(self, player: table|nil, signature: string|nil): nil
```

- `player: table` — player information. Contains the following properties:

```lua showLineNumbers
player = {
    logged_in: boolean,
    unique_id: string,
    name: string,
    photo: {
        small: string,
        medium: string,
        large: string
    }
}
```

**Example**

```lua showLineNumbers
function init_player()
    ysdk.player.get_info(function(self, player)
        if player then
            display_player(self, player)
        else
            ysdk.player.open_auth_dialog(function(self, authorized)
                ysdk.player.get_info(display_player, {})
            end)
        end
    end,
    {})
end

function display_player(player)
    if player then
        print(player.name, signature)
    end
end
```

## User Authorization {#auth}

If the player isn't logged in, you can use the `ysdk.player.open_auth_dialog()` method to call the authorization window.

```lua
ysdk.player.open_auth_dialog(callback: function)
```

`callback: function` — callback of the called method. Has the following form:

```lua
function(self, authorized: boolean): nil
```

- `authorized: boolean` — whether the player is authorized or not.

## In-game data {#ingame-data}

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

- `ysdk.player.set_data(data, flush)` — Saves the user data. The maximum data size must not exceed 200&nbsp;KB. {#setdata}
    - `data: table` — An object containing key-value pairs.
    - `flush: boolean` — Determines the order for sending data. If `true` is set, the data will be sent to the server immediately; `false` (default value) — the data sending request will be queued.

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

At `flush: false`, the returned result only shows the data validity (the data has been queued and will be sent later). At the same time, the `ysdk.player.get_data()` method will return the data set by the last `ysdk.player.set_data()`call, even if it has not been sent yet.

- `ysdk.player.get_data(callback, keys)` — requests the user's in-game data stored in the Yandex database.
    - `callback: fun(self, data: table<string, any>)` — handler function for processing the received in-game user data.
    - `keys: table<number, string>` — the list of keys to return. If the `keys` parameter is missing, the method returns all in-game user data.

- `ysdk.player.set_stats(stats)` — saves the user's numeric data. The maximum data size must not exceed 10&nbsp;KB.
    - `stats: table<string, number>` — object containing key-value pairs, where each value must be a number.

{% note info %}

For frequently changing numeric values (points, experience, in-game currency) use this method instead of [ysdk.player.set_data()](#setdata).

{% endnote %}

- `ysdk.player.increment_stats(increments)` — changes in-game user data. The maximum data size must not exceed 10&nbsp;KB.
    - `increments: table<string, number>` — an object containing key-value pairs, where each value must be a number.
- `ysdk.player.get_stats(callback, keys)` — retrieve the user's numerical data stored in the Yandex database.
    - `callback: fun(self, data: table<string, number>|nil)` — a handler function for working with the received numeric user data.
    - `keys: string[]` — a list of keys to return. If the `keys` parameter is missing, the method returns all in-game user data.

## User identifiers {#user-ids}

```lua
ysdk.player.get_ids_per_game(callback: function)
```

`callback: function` — callback of the invoked method. Has the following form:

```lua
function(self, ids: {appID: number, userID: string}[]): nil
```

- `ids` — user identifiers in all games of the developer, for which the user has explicitly consented to the transfer of personal data. Contains the following properties:
    - `app_id: string` — application ID.
    - `user_id: string` — user ID.

**Example**

```lua showLineNumbers
function log_ids()
    ysdk.player.get_ids_per_game(function(self, ids)
        for _, value in ipairs(ids) do
            print(value.app_id, value.user_id)
        end
    end)
end
```

---


<!-- source: en/_includes/sdk/button-git.md -->
<a href="https://github.com/yandex-games-plugins/defold">
  <span class="button">Repository</span>
</a>
<!-- endsource: en/_includes/sdk/button-git.md -->
