Version: stable
| CONSTANTS | |
|---|---|
| CONTENT_TYPE_VIDEO | |
| CONTENT_TYPE_PLAYABLE |
playables.is_in_playables_env()
Returns whether the SDK reports that the game is running in the Playables environment. Returns false if the SDK is not loaded.
PARAMETERS
None
RETURNS
boolean |
True when the SDK is loaded and IN_PLAYABLES_ENV is true, otherwise false. |
playables.get_sdk_version()
Returns the loaded YouTube Playables SDK version, or nil if it is unavailable.
PARAMETERS
None
RETURNS
stringnil |
The value of SDK_VERSION, or nil if the SDK or its version is unavailable. |
playables.game_ready()
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.
PARAMETERS
None
playables.load_data(callback)
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
callback |
function |
|
playables.save_data(data,callback)
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
data |
string |
The serialized game data as valid UTF-8 text. Embedded zero bytes are supported. | |||||||||
callback |
function |
|
playables.is_audio_enabled()
Returns whether game audio is enabled in the player's YouTube settings. Use this to initialize the game audio state.
PARAMETERS
None
RETURNS
boolean |
True when game audio is enabled. |
playables.on_audio_enabled_change(callback)
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
callback |
functionnil |
The event callback, or nil to unregister the current callback.
|
playables.on_pause(callback)
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
callback |
functionnil |
The event callback, or nil to unregister the current callback.
|
playables.on_resume(callback)
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
callback |
functionnil |
The event callback, or nil to unregister the current callback.
|
playables.get_language(callback)
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
callback |
function |
|
playables.send_score(score,callback)
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
score |
number |
An integer no greater than JavaScript's maximum safe integer. | |||||||||
callback |
function |
|
playables.open_yt_content(content_id,content_type,callback)
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
content_id |
string |
The YouTube video or Playable ID. | |||||||||
content_type |
number |
CONTENT_TYPE_VIDEO or CONTENT_TYPE_PLAYABLE. | |||||||||
callback |
function |
|
playables.request_interstitial_ad(callback)
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
callback |
function |
|
playables.request_rewarded_ad(reward_id,callback)
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
reward_id |
string |
A stable ID unique to the reward type. Reuse it for each offer of that reward and do not include user data. | |||||||||
callback |
function |
|
playables.log_error()
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.
PARAMETERS
None
playables.log_warning()
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.
PARAMETERS
None