Skip to content

Search

Belgeler

platform

Store services every platform shares: sign-in, achievements, leaderboards, cloud saves, purchases, a sign-in page in the OS's own sheet, local…

Bu sayfada

Store services every platform shares: sign-in, achievements, leaderboards, cloud saves, purchases, a sign-in page in the OS's own sheet, local notifications and push. A call answers task::wait later with a map whose kind is signed_in, signed_out, done, scores, read, identity, web_sign_in, notifications, scheduled, push_registered, push_failed, products, purchased, pending, entitlements, restored, finished, cancelled, error or unsupported, each an EVENT_* constant. What arrives unasked is the platform_event event, events::listen(node, "platform_event"): a sign-in or sign-out, a notification or a push tapped (notification_opened), one shown in front (notification_received) or a push that reached the game in front (push_received), a push token the OS replaced (push_token_changed), and a purchase that landed with nobody asking (transaction). is_available says whether a service works here. A test answers calls from the file BALAUR_STAND_INS names.

24 functions, 44 constants. Scripts reach it as platform::.

Functions

Argument kinds are the script values a call passes: node is a node handle, any a table or value of any kind, fn a callback.

function acts on what it does
backend() -> string — The name of the loaded store, or "none".
cancel_notification(string) — Drop a scheduled notification, and take a delivered one out of the shade.
close_web_sign_in() — Shut the sign-in page web_sign_in opened, once the game has what it opened it for: its call answers cancelled, and on Android the game comes back to the front over the tab.
cloud_read(string) -> int — Read a value the store syncs between the player's devices, and return the id whose read answer holds it as value: a string, or nil when the key holds nothing. On Play Games it is a saved game named key, and a conflict between two devices' saves resolves to the one modified last.
cloud_write(string, string) -> int — Write a value for the store to sync between the player's devices, and return the id its answer carries. On Play Games it is a saved game named key (letters, digits and -._~, up to 100), and a save another device made that Play has not reconciled with this one's is refused with error, never overwritten: read it, then write again.
entitlements() -> int — What this player owns now: return the id whose entitlements answer holds them as items, each a Transaction.
finish_purchase(string, platform::FinishPurchaseOptions?) -> int — Tell the store a purchase is dealt with, once a server has checked its token, and return the id its finished answer carries. One never finished comes back on every launch, and Play refunds one unacknowledged after three days.
identity() -> int — Ask the store for a proof of who is playing that a server checks with it, and return the id whose identity answer carries it: Steam's Web API ticket as ticket, hex, for ISteamUserAuth/AuthenticateUserTicket; Play Games' one-time server code as code, for [google] server_client_id, which the server exchanges with Google.
is_available(string) -> bool — Whether a service works on this device in this run, named by a SERVICE_* constant: the store or OS answers, a recording's answer in a replay, false where nothing reaches it.
notify(string, platform::NotifyOptions?) -> int — Schedule a local notification, and return the id its scheduled answer carries. A tap brings the game forward and is the platform_event event, notification_opened with the id and data; one shown while the game is in front is notification_received.
player() -> platform::Player? — Who the store says is playing, or nil before a sign-in has landed.
products([str]) -> int — Ask the store about a list of product ids, and return the id whose products answer holds what it knows, each a Product. An id the store does not know is left out.
progress(string, float) -> int — Report an achievement's completion, 0 to 100, and return the id its answer carries.
purchase(string) -> int — Buy a product in the store's own sheet, and return the id its answer carries: purchased with the Transaction's fields, cancelled or pending with product, or error. A pending one lands later as transaction on platform_event.
register_for_push() -> int — Ask the OS for this device's push token, and return the id whose push_registered answer carries it as token, with provider (PUSH_PROVIDER_APNS or PUSH_PROVIDER_FCM) and platform (PUSH_PLATFORM_IOS, a Mac's too, or PUSH_PLATFORM_ANDROID): the three fields Gamend's push_tokens::register_push_token takes, so the answer is handed to it as it is. push_failed says why with error, naming the capability to add when the export left it out ([apple] capabilities = ["push-notifications"], [android] capabilities = ["firebase-messaging"]); unsupported elsewhere. A token the OS replaces later is push_token_changed on platform_event, with the same fields. Showing a push needs request_notifications first, as a local notification does.
request_notifications() -> int — Ask the player to allow notifications, and return the id whose notifications answer says what they said as allowed. On Android 13 and later this is the system's permission prompt.
restore_purchases() -> int — Ask the store to hand this player's purchases back, the button a review expects a game to have, and return the id its restored answer carries; read them with entitlements after.
scores(string, platform::ScoresOptions?) -> int — Read a leaderboard's entries, and return the id whose scores answer holds them as entries, each a Score.
set_presence(string) -> int — Say what the player is doing, where the store shows it, and return the id its answer carries.
sign_in() -> int — Ask the store who is playing, and return the id its answer carries. A later sign-out is the platform_event event.
submit_score(string, int) -> int — Post a score to a leaderboard, and return the id its answer carries.
unlock(string) -> int — Award an achievement whole, and return the id its answer carries.
web_sign_in(string, platform::WebSignInOptions?) -> int — Open a sign-in page in the OS's own sheet over the game (a Custom Tab on Android), and return the id its answer carries: web_sign_in with the url it ended on when it reached opts.scheme, cancelled when shut, unsupported where the platform has no such sheet (open the page with engine::open_url there).
web_sign_in_state() -> string — How the page web_sign_in opened last stands, without waiting: PAGE_NONE before any, PAGE_OPEN while it has not answered, else the kind it answered. A game polling a server meanwhile reads it to hear the player shut the page.

Constants

name value
EVENT_CANCELLED "cancelled"
EVENT_DONE "done"
EVENT_ENTITLEMENTS "entitlements"
EVENT_ERROR "error"
EVENT_FINISHED "finished"
EVENT_IDENTITY "identity"
EVENT_NOTIFICATIONS "notifications"
EVENT_NOTIFICATION_OPENED "notification_opened"
EVENT_NOTIFICATION_RECEIVED "notification_received"
EVENT_PENDING "pending"
EVENT_PRODUCTS "products"
EVENT_PURCHASED "purchased"
EVENT_PUSH_FAILED "push_failed"
EVENT_PUSH_RECEIVED "push_received"
EVENT_PUSH_REGISTERED "push_registered"
EVENT_PUSH_TOKEN_CHANGED "push_token_changed"
EVENT_READ "read"
EVENT_RESTORED "restored"
EVENT_SCHEDULED "scheduled"
EVENT_SCORES "scores"
EVENT_SIGNED_IN "signed_in"
EVENT_SIGNED_OUT "signed_out"
EVENT_TRANSACTION "transaction"
EVENT_UNSUPPORTED "unsupported"
EVENT_WEB_SIGN_IN "web_sign_in"
PAGE_NONE "none"
PAGE_OPEN "open"
PUSH_PLATFORM_ANDROID "android"
PUSH_PLATFORM_IOS "ios"
PUSH_PROVIDER_APNS "apns"
PUSH_PROVIDER_FCM "fcm"
SERVICE_APPLE_SIGN_IN "apple_sign_in"
SERVICE_GAME_CENTER "game_center"
SERVICE_GOOGLE_SIGN_IN "google_sign_in"
SERVICE_HAPTICS "haptics"
SERVICE_ICLOUD "icloud"
SERVICE_NOTIFICATIONS "notifications"
SERVICE_PLAY_GAMES "play_games"
SERVICE_PURCHASES "purchases"
SERVICE_PUSH "push"
SERVICE_REVIEW "review"
SERVICE_SHARE "share"
SERVICE_STEAM "steam"
SERVICE_WEB_SIGN_IN "web_sign_in"

Emin misin?