extension-playables

Namespace: playables Language: Lua Type: Extension

Functions for interacting with the YouTube Playables SDK.

API

playables.is_in_playables_env

Type: FUNCTION Returns whether the SDK reports that the game is running in the Playables environment. Returns false if the SDK is not loaded.

Returns

playables.get_sdk_version

Type: FUNCTION Returns the loaded YouTube Playables SDK version, or nil if it is unavailable.

Returns

playables.game_ready

Type: FUNCTION Notifies YouTube that the loading screen is gone and the game is ready for players to interact with. The extension automatically calls firstFrameReady() during initialization.

playables.load_data

Type: FUNCTION Loads serialized game data from YouTube. Only one load request may be in progress at a time. The request remains in progress until its callback returns, so the callback cannot start another load_data() request.

Parameters

playables.save_data

Type: FUNCTION Saves valid UTF-8 text to YouTube, with a maximum size of 3 MiB. Invalid UTF-8 returns false and an error through the callback before the SDK is called. Base64-encode binary data such as sys.serialize() output before saving. Only one save request may be in progress at a time. The request remains in progress until its callback returns, so the callback cannot start another save_data() request.

Parameters

playables.is_audio_enabled

Type: FUNCTION Returns whether game audio is enabled in the player’s YouTube settings. Use this to initialize the game audio state.

Returns

playables.on_audio_enabled_change

Type: FUNCTION Registers a callback for YouTube audio-setting changes. Before the callback runs, the extension automatically mutes the master sound group when audio is disabled, or unmutes it when audio is enabled and the game is not paused. A new callback replaces the previous one. Pass nil to unregister it. This function cannot be called from its own callback.

Parameters

playables.on_pause

Type: FUNCTION Registers a callback for YouTube pause events. The extension automatically mutes the master sound group before the callback runs. A new callback replaces the previous one. Pass nil to unregister it. This function cannot be called from its own callback. A paused game is not guaranteed to resume.

Parameters

playables.on_resume

Type: FUNCTION Registers a callback for YouTube resume events. Before the callback runs, the extension automatically unmutes the master sound group if YouTube audio is enabled, or keeps it muted if audio is disabled. A new callback replaces the previous one. Pass nil to unregister it. This function cannot be called from its own callback.

Parameters

playables.get_language

Type: FUNCTION Gets the language in the player’s YouTube settings as a BCP-47 language tag. Only one request may be in progress at a time. The request remains in progress until its callback returns, so the callback cannot start another get_language() request.

Parameters

playables.send_score

Type: FUNCTION Sends an integer score to YouTube. Use one consistent score dimension across the game. Only one request may be in progress at a time. The request remains in progress until its callback returns, so the callback cannot start another send_score() request.

Parameters

playables.open_yt_content

Type: FUNCTION Requests that YouTube open a video or another Playable. The content type is optional and defaults to CONTENT_TYPE_VIDEO. Only one request may be in progress at a time. The request remains in progress until its callback returns, so the callback cannot start another open_yt_content() request.

Parameters

playables.request_interstitial_ad

Type: FUNCTION Requests an interstitial ad. Success does not guarantee that an ad was shown. Do not use this API to grant rewards. Only one interstitial request may be in progress at a time. The request remains in progress until its callback returns, so the callback cannot start another request_interstitial_ad() request. Keep handling YouTube audio, pause, and resume events during ads.

Parameters

playables.request_rewarded_ad

Type: FUNCTION Requests a rewarded ad. Grant a reward only when reward_earned is true. Only one rewarded request may be in progress at a time. The request remains in progress until its callback returns, so the callback cannot start another request_rewarded_ad() request. Keep handling YouTube audio, pause, and resume events during ads.

Parameters

playables.log_error

Type: FUNCTION Reports an error occurrence to YouTube. Takes no arguments and returns no value. Reporting is best-effort and rate-limited, so delivery is not guaranteed.

playables.log_warning

Type: FUNCTION Reports a warning occurrence to YouTube. Takes no arguments and returns no value. Reporting is best-effort and rate-limited, so delivery is not guaranteed.

CONTENT_TYPE_VIDEO

Type: VARIABLE Opens a YouTube video.

CONTENT_TYPE_PLAYABLE

Type: VARIABLE Opens another YouTube Playable.