Player data
You can save the game state data (completed levels, experience, in-game purchases, etc.) on the Yandex server or send it to your own server. You can also personalize the game using some data from the user's profile on Yandex, such as the name.
Player information
ysdk.player.get_info(
callback: function,
options: {
scopes: boolean|nil,
signed: boolean|nil
}
)
callback: function
— the callback of the called method. It looks like this:
function(self, player: table|nil, signature: string|nil): nil
player: table
— player information. Contains properties:player = {
logged_in: boolean,
unique_id: string,
name: string,
photo: {
small: string,
medium: string,
large: string
}
}signature: string
— signature of the player's data.
Example
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
If the player is not authorized, you can use the ysdk.player.open_auth_dialog()
method
to call the authorization window.
ysdk.player.open_auth_dialog(callback: function)
callback: function
— the callback of the called method. It looks like this:
function(self, authorized: boolean):
authorized: boolean
— whether the player is authorized or not.
In-game data
To work with user in-game data, use the methods of the Player
object:
-
ysdk.player.set_data(data, flush)
— saves user data. The maximum data size should not exceed 200 KB.data: table
— contains key-value pairs.flush: boolean
— determines the order of data sending. Iftrue
, the data will be sent to the server immediately;false
(default) — the request to send the data will be queued.
The method returns a
Promise
that shows whether the data was saved or not.When the
flush: false
parameter is set, the returned result only shows the validity of the data (the sending itself is queued and will be done later). At the same time, theysdk.player.get_data()
method will return the data set by the lastysdk.player.set_data()
call, even if it has not been sent yet. -
ysdk.player.get_data(callback, keys)
— requests user in-game data saved in the Yandex database.callback: fun(self, data: table<string, any>)
— a handler function to work with the received user in-game data.keys: table<number, string>
— a list of keys to return. If thekeys
parameter is missing, the method returns all user in-game data.
-
ysdk.player.set_stats(stats)
— saves user numerical data. The maximum data size should not exceed 10 KB.stats: table<string, number>
— contains key-value pairs, where each value should be a number.
Use this method for frequently changing numerical values (scores, experience points, in-game currency) instead of ysdk.player.set_data().
ysdk.player.increment_stats(increments)
— changes user in-game data. The maximum data size should not exceed 10 KB.increments: table<string, number>
— an object that contains key-value pairs, where each value should be a number.
ysdk.player.get_stats(callback, keys)
— gets user numerical data saved in the Yandex database.callback: fun(self, data: table<string, number>|nil)
— a handler function to work with the received numerical user data.keys: string[]
— a list of keys to return. If thekeys
parameter is missing, the method returns all user in-game data.
User identifiers
ysdk.player.get_ids_per_game(callback: function)
callback: function
— the callback of the called method. It looks like this:
function(self, ids: {appID: number, userID: string}[]): nil
ids
- user identifiers in all developer games where the user has given explicit consent to transfer personal data. Contains properties:app_id: string
— application identifier.user_id: string
— user identifier.
Example
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