indiesoftby/defold-yagames/yagames
YaGames is the Yandex.Games SDK implementation for the Defold game engine.
- GitHub: indiesoftby/defold-yagames — pinned to
0.19.0- Pick a release from indiesoftby/defold-yagames releases and add its Source code (zip) URL (or a packaged
.zipasset, if the library ships one) togame.projectunder[project]dependencies, then Fetch Libraries in the Defold editor. - Run
bunx @defold-typescript/cli resolveto materialize its types. - Import it under a namespace alias of your choice:
import * as yagames from "yagames.yagames"
- Pick a release from indiesoftby/defold-yagames releases and add its Source code (zip) URL (or a packaged
Functions
init(callback:ApiCallback)adv_show_fullscreen_adv(callbacks:AdvCallbacks)adv_show_rewarded_video(callbacks:RewardedCallbacks)adv_get_banner_adv_status(callback:StickyBannerCallback)adv_show_banner_adv(callback?:StickyBannerCallback)adv_hide_banner_adv(callback?:StickyBannerHideCallback)auth_open_auth_dialog(callback:ApiCallback)player_init(options:PlayerInitOptions, callback:ApiCallback)player_set_data(data: Record<string, unknown>, flush: boolean, callback:ApiCallback)player_get_data(keys: Array<string> | undefined, callback:ApiCallback)player_set_stats(stats: Record<string, number>, callback:ApiCallback)player_increment_stats(stats: Record<string, number>, callback:ApiCallback)player_get_stats(keys: Array<string> | undefined, callback:ApiCallback)player_get_id(): stringplayer_get_unique_id(): stringplayer_get_name(): stringplayer_get_ids_per_game(callback:PlayerGetIdsCallback)player_get_photo(size: 'small' | 'medium' | 'large'): stringplayer_get_paying_status(): 'paying' | 'partially_paying' | 'not_paying' | 'unknown'player_get_personal_info():PlayerPersonalInfo| undefinedplayer_get_signature(): string | undefinedplayer_get_mode(): 'lite' | ''player_is_authorized(): booleanpayments_init(options: { signed?: boolean; } | undefined, callback:ApiCallback)payments_purchase(options:PaymentsPurchaseOptions| undefined, callback:PaymentsPurchaseCallback)payments_get_purchases(callback:PaymentsPurchasesCallback)payments_get_catalog(options:PaymentsCatalogOptions| undefined, callback:PaymentsCatalogCallback)payments_consume_purchase(purchase_token: string, callback:ApiCallback)leaderboards_init(callback:ApiCallback)leaderboards_get_description(leaderboard_name: string, callback:LeaderboardsDescriptionCallback)leaderboards_get_player_entry(leaderboard_name: string, options:LeaderboardsGetPlayerEntryOptions| undefined, callback:ApiCallback)leaderboards_get_entries(leaderboard_name: string, options:LeaderboardsGetEntriesOptions| undefined, callback:LeaderboardsGetPlayerEntriesCallback)leaderboards_set_score(leaderboard_name: string, score: number, extra_data: string, callback:ApiCallback)features_loadingapi_ready()features_gameplayapi_start()features_gameplayapi_stop()features_gamesapi_get_all_games(callback:GamesApiAllGamesCallback)features_gamesapi_get_game_by_id(app_id: number, callback:GamesApiGameByIdCallback)feedback_can_review(callback:FeedbackCanReviewCallback)feedback_request_review(callback:FeedbackCanReviewCallback)clipboard_write_text(text: string, callback?:ApiCallback)device_info_type(): "desktop" | "mobile" | "tablet"device_info_is_desktop(): booleandevice_info_is_mobile(): booleandevice_info_is_tablet(): booleandevice_info_is_tv(): booleanenvironment():EnvironmentResultsscreen_fullscreen_status(): "on" | "off"screen_fullscreen_request(callback?:ApiCallback)screen_fullscreen_exit(callback?:ApiCallback)shortcut_can_show_prompt(callback:ShortcutCanShowCallback)shortcut_show_prompt(callback?:ShortcutShowPromptCallback)storage_init(callback:ApiCallback)storage_get_item(key: string): string | undefinedstorage_set_item(key: string, value: string)storage_remove_item(key: string)storage_clear()storage_key(n: number): string | undefinedstorage_length(): numberflags_get(options:FlagsOptions| undefined, callback:FlagsCallback)event_on(event_name: string, listener:ApiCallback)event_off(event_name: string, listener:ApiCallback)event_dispatch(event_name: string)multiplayer_sessions_init(options:MultiplayerSessionsInitOptions, callback:MultiplayerSessionsInitCallback)multiplayer_sessions_commit(data: Record<string, unknown>)multiplayer_sessions_push(data:MultiplayerSessionsPushMeta)is_available_method(name: string, callback:AvailableMethodCallback)server_time(): number
init(callback: ApiCallback)U
Initializes YaGames extension and waits for Yandex.Games SDK initialization
Parameters
callback:ApiCallback— Callback arguments are (self, err). If err is not nil, something is wrong.
adv_show_fullscreen_adv(callbacks: AdvCallbacks)U
Calls the fullscreen ad. Fullscreen ad block - advertising blocks that completely cover the game background and are shown when a player waits for something (for example, when switching to the next level of the game).
Parameters
callbacks:AdvCallbacks—open- Called when an ad is opened successfully.close- Called when an ad is closed, an error occurred, or on ad failed to open due to too frequent calls. Used with thewas_shownargument (typeboolean), the value of which indicates whether an ad was shown.offline- Called when the network connection is lost (when offline mode is enabled).error- Called when an error occurrs. The error object is passed to the callback function.
adv_show_rewarded_video(callbacks: RewardedCallbacks)U
Calls the rewarded video ad. Rewarded videos are video ad blocks used to monetize games and earn a reward or in-game currency.
Parameters
callbacks:RewardedCallbacks—open- Called when a video ad is displayed on the screen.rewarded- Called when a video ad impression is counted. Use this function to specify a reward for viewing the video ad.close- Called when a user closes a video ad or an error happens.error- Called when an error occurrs. The error object is passed to the callback function.
adv_get_banner_adv_status(callback: StickyBannerCallback)U
Receives Sticky-banner ad status.
Parameters
callback:StickyBannerCallback— Callback arguments are (self, err, result), whereresultis { stickyAdvIsShowing = boolean, reason = "string" }
adv_show_banner_adv(callback?: StickyBannerCallback)U
Shows Sticky-banner.
Parameters
callback?:StickyBannerCallback
adv_hide_banner_adv(callback?: StickyBannerHideCallback)U
Hides Sticky-banner.
Parameters
callback?:StickyBannerHideCallback
auth_open_auth_dialog(callback: ApiCallback)U
Opens the login dialog box.
Parameters
callback:ApiCallback
player_init(options: PlayerInitOptions, callback: ApiCallback)U
Initializes the "player" system.
Parameters
options:PlayerInitOptionscallback:ApiCallback— Callback arguments are (self, err)
player_set_data(data: Record<string, unknown>, flush: boolean, callback: ApiCallback)U
Saves user data. The maximum data size should not exceed 200 KB.
Parameters
data:Record<string, unknown>— A table containing key-value pairs. Example: { "a" = "value", "b" = 2 }.flush:boolean— Specifies the order data is sent. If the value is “true”, the data is immediately sent to the server. If it's “false” (default), the request to send data is queued.callback:ApiCallback— Callback arguments are (self, err)
player_get_data(keys: Array<string> | undefined, callback: ApiCallback)U
Asynchronously returns the in-game user data stored in the Yandex database.
Parameters
keys:Array<string> | undefinedcallback:ApiCallback— Callback arguments are (self, err, result), whereresultare pairs as key-values, i.e. { "a" = "value", "b" = 2 }.
player_set_stats(stats: Record<string, number>, callback: ApiCallback)U
Save the user's numeric data. The maximum data size must not exceed 10 KB.
Parameters
stats:Record<string, number>callback:ApiCallback— Callback arguments are (self, err, result), whereresultare changed pairs as key-values, i.e. { "a" = 1, "b" = 2 }.
player_increment_stats(stats: Record<string, number>, callback: ApiCallback)U
Change in-game user data. The maximum data size must not exceed 10 KB.
Parameters
stats:Record<string, number>callback:ApiCallback— Callback arguments are (self, err, result), whereresultare changed pairs as key-values, i.e. { "a" = 10, "b" = 5 }.
player_get_stats(keys: Array<string> | undefined, callback: ApiCallback)U
Asynchronously returns the user's numeric data.
Parameters
keys:Array<string> | undefined— List of keys to be returned (example { "a", "b", "key1", "key2" }). If the keys parameter is nil, the method returns all in-game user data.callback:ApiCallback— Callback arguments are (self, err, result), whereresultare pairs as key-values, i.e. { "a" = 1, "b" = 2 }.
player_get_id(): stringU
- Deprecated — Use
player_get_unique_idinstead.
Return the user's ID.
Returns
string
player_get_unique_id(): stringU
Returns the user's unique permanent ID.
Returns
string
player_get_name(): stringU
Return the user's name.
Returns
string
player_get_ids_per_game(callback: PlayerGetIdsCallback)U
Return table (=array), where the user IDs are specified in all developer games in which the user has explicitly consented to the transfer of their personal data.
Parameters
callback:PlayerGetIdsCallback
player_get_photo(size: 'small' | 'medium' | 'large'): stringU
Return the URL of the user's avatar.
Parameters
size:'small' | 'medium' | 'large'
Returns
string
player_get_paying_status(): 'paying' | 'partially_paying' | 'not_paying' | 'unknown'U
Returns four possible values (type: string) depending on the frequency and volume of the user's purchases.
Returns
'paying' | 'partially_paying' | 'not_paying' | 'unknown'
player_get_personal_info(): PlayerPersonalInfo | undefinedU
Returns a table with player data
Returns
PlayerPersonalInfo | undefined— or nil
player_get_signature(): string | undefinedU
Returns string with the user's data from player's Yandex profile and the signature. It consists of two Base64-encoded strings.
Returns
string | undefined
player_get_mode(): 'lite' | ''U
- Deprecated — Use
player_is_authorizedinstead.
Return the user's auth mode.
Returns
'lite' | ''
player_is_authorized(): booleanU
Return the user's auth mode.
Returns
boolean
payments_init(options: { signed?: boolean; } | undefined, callback: ApiCallback)U
Initializes the in-game purchases system.
Parameters
options:{ signed?: boolean; } | undefinedcallback:ApiCallback— Callback arguments are (self, err)
payments_purchase(options: PaymentsPurchaseOptions | undefined, callback: PaymentsPurchaseCallback)U
Activate an in-game purchase.
Parameters
options:PaymentsPurchaseOptions | undefinedcallback:PaymentsPurchaseCallback
payments_get_purchases(callback: PaymentsPurchasesCallback)U
Find out what purchases a player already made.
Parameters
callback:PaymentsPurchasesCallback
payments_get_catalog(options: PaymentsCatalogOptions | undefined, callback: PaymentsCatalogCallback)U
Get a list of available purchases and their cost.
Parameters
options:PaymentsCatalogOptions | undefinedcallback:PaymentsCatalogCallback
payments_consume_purchase(purchase_token: string, callback: ApiCallback)U
Consume an in-game purchase. There are two types of purchases: permanent (such as for disabling ads) and consumable (such as in-game currency). To process consumable purchases, use this function.
Parameters
purchase_token:stringcallback:ApiCallback
leaderboards_init(callback: ApiCallback)U
- Deprecated — The leaderboards subsystem no longer needs initializing; the other
leaderboards_*functions work without it.
Initializes the leaderboards subsystem.
Parameters
callback:ApiCallback— Callback arguments are (self, err)
leaderboards_get_description(leaderboard_name: string, callback: LeaderboardsDescriptionCallback)U
Get a description of a leaderboard by name.
Parameters
leaderboard_name:stringcallback:LeaderboardsDescriptionCallback— Callback arguments are (self, err, result), whereresultis a table with leaderboard description.
leaderboards_get_player_entry(leaderboard_name: string, options: LeaderboardsGetPlayerEntryOptions | undefined, callback: ApiCallback)U
Get a player's ranking.
Parameters
leaderboard_name:stringoptions:LeaderboardsGetPlayerEntryOptions | undefinedcallback:ApiCallback— Callback arguments are (self, err, result), whereresultis a table with player's ranking.
leaderboards_get_entries(leaderboard_name: string, options: LeaderboardsGetEntriesOptions | undefined, callback: LeaderboardsGetPlayerEntriesCallback)U
Gets player's rankings.
Parameters
leaderboard_name:stringoptions:LeaderboardsGetEntriesOptions | undefinedcallback:LeaderboardsGetPlayerEntriesCallback— Callback arguments are (self, err, result), whereresultis a table with data about leaderboard entries.
leaderboards_set_score(leaderboard_name: string, score: number, extra_data: string, callback: ApiCallback)U
Sets a new score for a player.
Parameters
leaderboard_name:stringscore:numberextra_data:stringcallback:ApiCallback— Callback arguments are (self, err)
features_loadingapi_ready()U
Informs the SDK that the game has loaded and is ready to play.
features_gameplayapi_start()U
The method should be called when the player starts or resumes gameplay.
features_gameplayapi_stop()U
The method should be called when the player stops or pauses gameplay.
features_gamesapi_get_all_games(callback: GamesApiAllGamesCallback)U
Get information about all your games available on the current platform and domain.
Parameters
callback:GamesApiAllGamesCallback
features_gamesapi_get_game_by_id(app_id: number, callback: GamesApiGameByIdCallback)U
Get a game by ID.
Parameters
app_id:numbercallback:GamesApiGameByIdCallback
feedback_can_review(callback: FeedbackCanReviewCallback)U
Finds out if it is possible to request a feedback window for the game.
Parameters
callback:FeedbackCanReviewCallback— Callback arguments are (self, err, result), whereresultis { value = boolean, [reason] = "string" }
feedback_request_review(callback: FeedbackCanReviewCallback)U
Offers the user to rate the game.
Parameters
callback:FeedbackCanReviewCallback— Callback arguments are (self, err, result), whereresultis { feedbackSent = boolean }
clipboard_write_text(text: string, callback?: ApiCallback)U
Writes a string to the clipboard.
Parameters
text:stringcallback?:ApiCallback
device_info_type(): "desktop" | "mobile" | "tablet"U
Returns the type of the user's device.
Returns
"desktop" | "mobile" | "tablet"— "desktop" (computer), "mobile" (mobile device), "tablet" (tablet) or "tv" (TV)
device_info_is_desktop(): booleanU
Checks the user's device and returns "true" if it's a desktop.
Returns
boolean
device_info_is_mobile(): booleanU
Checks the user's device and returns "true" if it's a mobile.
Returns
boolean
device_info_is_tablet(): booleanU
Checks the user's device and returns "true" if it's a tablet.
Returns
boolean
device_info_is_tv(): booleanU
Checks the user's device and returns "true" if it's a TV.
Returns
boolean
environment(): EnvironmentResultsU
Returns a table with game environment variables.
Returns
EnvironmentResults
screen_fullscreen_status(): "on" | "off"U
Gets the current fullscreen state: "on" or "off".
Returns
"on" | "off"
screen_fullscreen_request(callback?: ApiCallback)U
Requests entering fullscreen mode.
Parameters
callback?:ApiCallback— Callback arguments are (self, err)
screen_fullscreen_exit(callback?: ApiCallback)U
Request exit from fullscreen mode.
Parameters
callback?:ApiCallback— Callback arguments are (self, err)
shortcut_can_show_prompt(callback: ShortcutCanShowCallback)U
Check if a shortcut can be added.
Parameters
callback:ShortcutCanShowCallback— Callback arguments are (self, err, result), whereresultis { canShow = boolean }
shortcut_show_prompt(callback?: ShortcutShowPromptCallback)U
Show a prompt to the user to add a shortcut to the game.
Parameters
callback?:ShortcutShowPromptCallback— Callback arguments are (self, err, result), whereresultis { outcome = string }
storage_init(callback: ApiCallback)U
Initialize the Safe Storage
Parameters
callback:ApiCallback
storage_get_item(key: string): string | undefinedU
Returns that key's value or nil.
Parameters
key:string
Returns
string | undefined
storage_set_item(key: string, value: string)U
Adds that key to the storage, or update that key's value if it already exists.
Parameters
key:stringvalue:string
storage_remove_item(key: string)U
Removes that key from the storage.
Parameters
key:string
storage_clear()U
Empties all keys out of the storage.
storage_key(n: number): string | undefinedU
Returns the name of the nth key in the storage.
Parameters
n:number
Returns
string | undefined
storage_length(): numberU
Returns the number of data items stored in the storage.
Returns
number
flags_get(options: FlagsOptions | undefined, callback: FlagsCallback)U
Asynchronously get remote config data
Parameters
options:FlagsOptions | undefinedcallback:FlagsCallback
event_on(event_name: string, listener: ApiCallback)U
Add an event listener.
Parameters
event_name:stringlistener:ApiCallback
event_off(event_name: string, listener: ApiCallback)U
Remove an event listener.
Parameters
event_name:stringlistener:ApiCallback
event_dispatch(event_name: string)U
Dispatch an event.
Parameters
event_name:string
multiplayer_sessions_init(options: MultiplayerSessionsInitOptions, callback: MultiplayerSessionsInitCallback)U
Initialize the multiplayer sessions. If isEventBased is true, you must subscribe to the events multiplayer-sessions-transaction and multiplayer-sessions-finish through yagames.event_on(event_name, listener), and the SDK itself will load the session and events at the specified timestamps.
Note: To load sessions, you must set at least one of the 3 meta-parameters, and the count parameter must be greater than zero. Otherwise, the multiplayer will be initialized only for writing data.
Parameters
options:MultiplayerSessionsInitOptionscallback:MultiplayerSessionsInitCallback— Callback arguments are (self, err, result), whereresultis table (array)
multiplayer_sessions_commit(data: Record<string, unknown>)U
Commit the multiplayer session
Parameters
data:Record<string, unknown>
multiplayer_sessions_push(data: MultiplayerSessionsPushMeta)U
Push the multiplayer session
Parameters
data:MultiplayerSessionsPushMeta
is_available_method(name: string, callback: AvailableMethodCallback)U
Checks if the method is available to call
Parameters
name:stringcallback:AvailableMethodCallback
server_time(): numberU
Get server time in UNIX format.
Returns
number
Variables
ysdk_ready: boolean
true once init has succeeded; the calls that need the SDK assert it before they run.
payments_ready: boolean
true after the latest payments_init succeeded; the purchase calls assert it before they run.
player_ready: boolean
true after the latest player_init succeeded; the player calls assert it before they run.
banner_ready: boolean
Starts as false, and no call in this version of the library sets it, so it stays false.