Playgama/bridge-defold/bridge
Functions and constants for interacting with bridge
- GitHub: Playgama/bridge-defold — pinned to
v2.4.4- Pick a release from Playgama/bridge-defold 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 bridge from "bridge"
- Pick a release from Playgama/bridge-defold releases and add its Source code (zip) URL (or a packaged
Functions
bridge.platform.on(event_name: string, callback: function)bridge.platform.id(): string | nilbridge.platform.tld(): string | nilbridge.platform.language(): stringbridge.platform.payload(): string | nilbridge.platform.launch_source(): string | nilbridge.platform.data(): tablebridge.platform.send_message(message: string, options: table, on_success: function, on_failure: function)bridge.platform.send_custom_message(id: string, options: table, on_success: function, on_failure: function)bridge.platform.get_server_time(on_success: function, on_failure: function)bridge.platform.is_audio_enabled(): booleanbridge.platform.is_external_calls_supported(): booleanbridge.platform.is_external_links_allowed(): booleanbridge.cross_promo.get_games(on_success: function, on_failure: function)bridge.cross_promo.show()bridge.cross_promo.hide()bridge.cross_promo.is_visible(): booleanbridge.storage.get(table_keys: table, on_success: function, on_failure: function)bridge.storage.set(table_data: table, on_success: function, on_failure: function)bridge.storage.delete(table_keys: table, on_success: function, on_failure: function)bridge.advertisement.show_banner(position: string, placement: string)bridge.advertisement.hide_banner()bridge.advertisement.banner_state()bridge.advertisement.is_banner_supported(): stringbridge.advertisement.is_interstitial_supported(): stringbridge.advertisement.is_rewarded_supported(): stringbridge.advertisement.on(event_name: string, callback: function)bridge.advertisement.show_interstitial(placement: string)bridge.advertisement.interstitial_state()bridge.advertisement.minimum_delay_between_interstitial(): numberbridge.advertisement.set_minimum_delay_between_interstitial(delay: number)bridge.advertisement.rewarded_state()bridge.advertisement.rewarded_placement()bridge.advertisement.show_rewarded(placement: string)bridge.advertisement.is_advanced_banners_supported(): stringbridge.advertisement.advanced_banners_state()bridge.advertisement.show_advanced_banners(placement: string)bridge.advertisement.hide_advanced_banners()bridge.advertisement.check_ad_block(on_success: function, on_failure: function)bridge.device.type(): stringbridge.player.is_authorization_supported(): booleanbridge.player.is_authorized(): booleanbridge.player.is_guest(): booleanbridge.player.id(): string | nilbridge.player.name(): string | nilbridge.player.extra(): tablebridge.player.photos(): tablebridge.player.authorize(options: table, on_success: function, on_failure: function)bridge.social.is_share_supported(): booleanbridge.social.share(id: string, on_success: function, on_failure: function)bridge.social.is_join_community_supported(): booleanbridge.social.join_community(on_success: function, on_failure: function)bridge.social.is_invite_friends_supported(): booleanbridge.social.invite_friends(id: string, on_success: function, on_failure: function)bridge.social.is_create_post_supported(): booleanbridge.social.create_post(id: string, payload: string, on_success: function, on_failure: function)bridge.social.is_add_to_favorites_supported(): booleanbridge.social.add_to_favorites(on_success: function, on_failure: function)bridge.social.is_add_to_home_screen_supported(): booleanbridge.social.add_to_home_screen(on_success: function, on_failure: function)bridge.social.is_rate_supported(): booleanbridge.social.rate(on_success: function, on_failure: function)bridge.social.is_post_reward_supported(): booleanbridge.social.get_post_reward(on_success: function, on_failure: function)bridge.payments.is_supported(): booleanbridge.payments.purchase(id: string, on_success: function, on_failure: function)bridge.payments.consume_purchase(id: string, on_success: function, on_failure: function)bridge.payments.get_catalog(on_success: function, on_failure: function)bridge.payments.get_purchases(on_success: function, on_failure: function)bridge.achievements.unlock(id: string, on_success: function, on_failure: function)bridge.achievements.get_achievements(on_success: function, on_failure: function)bridge.daily_rewards.get_rewards(on_success: function, on_failure: function)bridge.daily_rewards.get_current_day(on_success: function, on_failure: function)bridge.daily_rewards.get_current_reward(on_success: function, on_failure: function)bridge.daily_rewards.claim_current_reward(on_success: function, on_failure: function)bridge.tasks.get_tasks(on_success: function, on_failure: function)bridge.tasks.add_progress(metric: string, amount: number, on_success: function, on_failure: function)bridge.tasks.claim_reward(task_id: string, on_success: function, on_failure: function)bridge.leaderboards.type(): stringbridge.leaderboards.set_score(id: string, score: number, on_success: function, on_failure: function)bridge.leaderboards.get_entries(id: string, on_success: function, on_failure: function)bridge.leaderboards.show_native_popup(id: string, on_success: function, on_failure: function)bridge.remote_config.is_supported(): booleanbridge.remote_config.set_context(parameters: table)bridge.remote_config.get(on_success: function, on_failure: function)bridge.notifications.is_supported(): booleanbridge.notifications.schedule(notification: table, on_success: function, on_failure: function)bridge.notifications.cancel(id: string, on_success: function, on_failure: function)bridge.notifications.cancel_all(on_success: function, on_failure: function)bridge.analytics.send(event_name: string, data: table)bridge.multiplayer.on(event_name: string, callback: function)bridge.multiplayer.is_supported(): booleanbridge.multiplayer.state(): stringbridge.multiplayer.is_in_room(): booleanbridge.multiplayer.is_host(): booleanbridge.multiplayer.player_id(): string | nilbridge.multiplayer.host_id(): string | nilbridge.multiplayer.room_id(): string | nilbridge.multiplayer.region(): string | nilbridge.multiplayer.room(): table | nilbridge.multiplayer.players(): tablebridge.multiplayer.is_invite_supported(): booleanbridge.multiplayer.launch_room_id(): string | nilbridge.multiplayer.sync_state(): tablebridge.multiplayer.create_room(options: table, on_success: function, on_failure: function)bridge.multiplayer.join_room(room_id: string, options: table, on_success: function, on_failure: function)bridge.multiplayer.join_or_create_room(options: table, on_success: function, on_failure: function)bridge.multiplayer.get_rooms(options: table, on_success: function, on_failure: function)bridge.multiplayer.get_regions(on_success: function, on_failure: function)bridge.multiplayer.set_region(region: string)bridge.multiplayer.invite_to_room(options: table, on_success: function, on_failure: function)bridge.multiplayer.leave_room()bridge.multiplayer.set_room_open(is_open: boolean)bridge.multiplayer.set_room_visible(is_visible: boolean)bridge.multiplayer.set_room_properties(properties: table)bridge.multiplayer.set_player_properties(properties: table)bridge.multiplayer.send(message_type: string, data: table | string | number | boolean | nil, options: table)bridge.multiplayer.set_sync_state(state: table)
bridge.platform.on(event_name: string, callback: function)
State changed events.
Parameters
event_name:stringcallback:function— function(_, state)
bridge.platform.id(): string | nil
Identify the platform on which the game is currently running to customize features and settings accordingly.
Returns
result:string | nil
bridge.platform.tld(): string | nil
Retrieve the top-level domain of the platform to handle domain-specific configurations and behavior.
Returns
result:string | nil
bridge.platform.language(): string
Get the language set by the user on the platform or the browser language if not provided by the platform, to localize game content.
Returns
result:string
bridge.platform.payload(): string | nil
Embed auxiliary information into the game URL to pass additional data or settings when launching the game.
Returns
result:string | nil
bridge.platform.launch_source(): string | nil
Where the game was opened from - "notification" or "post" (one of the game's own posts, see bridge.social.create_post). nil when the platform did not say.
Returns
result:string | nil
bridge.platform.data(): table
Everything the launch carries - the parameters the platform passed to the game and, when it was opened from one of the game's own posts, postId - the id of that post's config entry.
Returns
result:table
bridge.platform.send_message(message: string, options: table, on_success: function, on_failure: function)
Send predefined messages to the platform to trigger specific actions or events, such as signaling that the game is ready.
Parameters
message:string— One of message types:game_readyin_game_loading_startedoptions:table— Optional message-specific options (may be omitted).on_success:functionon_failure:function
bridge.platform.send_custom_message(id: string, options: table, on_success: function, on_failure: function)
Send a custom message with an arbitrary id to the platform.
Parameters
id:string— The custom message id.options:table— Optional message-specific options (may be omitted).on_success:functionon_failure:function
bridge.platform.get_server_time(on_success: function, on_failure: function)
Server Time
Parameters
on_success:function— function(_, time)on_failure:function— function(_, error)
bridge.platform.is_audio_enabled(): boolean
Check if the audio is enabled on the platform.
Returns
result:boolean
bridge.platform.is_external_calls_supported(): boolean
Check if external calls are supported on the platform.
Returns
result:boolean
bridge.platform.is_external_links_allowed(): boolean
Check if external links are allowed on the platform.
Returns
result:boolean
bridge.cross_promo.get_games(on_success: function, on_failure: function)
Get the cross-promo games list. Resolves to an empty array when unsupported. Each game has the shape { id, name, url, icon_url, cover_url, payload }.
Parameters
on_success:function— function(_, games)on_failure:function— function(_, error)
bridge.cross_promo.show()
Show the built-in cross-promo HTML overlay.
bridge.cross_promo.hide()
Hide the built-in cross-promo HTML overlay.
bridge.cross_promo.is_visible(): boolean
Check whether the cross-promo overlay is currently shown.
Returns
result:boolean
bridge.storage.get(table_keys: table, on_success: function, on_failure: function)
Retrieve stored data based on a key or multiple keys to restore player progress or settings.
Parameters
table_keys:tableon_success:function— function(_, data)on_failure:function— function(_, error)
bridge.storage.set(table_data: table, on_success: function, on_failure: function)
Save data to the storage with a key to retain player progress or settings.
Parameters
table_data:tableon_success:function— function(_)on_failure:function— function(_, error)
bridge.storage.delete(table_keys: table, on_success: function, on_failure: function)
Remove data from the storage by key to manage player data and settings effectively.
Parameters
table_keys:tableon_success:function— function(_)on_failure:function— function(_, error)
bridge.advertisement.show_banner(position: string, placement: string)
Display a banner ad within your game to generate revenue through advertising.
Parameters
position:stringplacement:string
bridge.advertisement.hide_banner()
Hide the currently displayed banner ad when it is no longer needed.
bridge.advertisement.banner_state()
Hide the currently displayed banner ad when it is no longer needed.
bridge.advertisement.is_banner_supported(): string
Check if the platform supports displaying banner ads. Use this to determine if you can include banner advertisements in your game.
Returns
result:string
bridge.advertisement.is_interstitial_supported(): string
Check if the platform supports displaying interstitial ads. Use this to determine if you can include interstitial advertisements in your game.
Returns
result:string
bridge.advertisement.is_rewarded_supported(): string
Check if the platform supports displaying rewarded ads. Use this to determine if you can include rewarded advertisements in your game.
Returns
result:string
bridge.advertisement.on(event_name: string, callback: function)
State changed events.
Parameters
event_name:stringcallback:function— function(_, state)
bridge.advertisement.show_interstitial(placement: string)
Display an interstitial ad at appropriate moments, such as during level transitions or game over screens.
Parameters
placement:string
bridge.advertisement.interstitial_state()
Track the state of the interstitial ad to manage ad display and user experience.
bridge.advertisement.minimum_delay_between_interstitial(): number
Minimum time interval between interstitial ad displays to comply with platform requirements and improve user experience.
Returns
result:number
bridge.advertisement.set_minimum_delay_between_interstitial(delay: number)
Set the minimum time interval between interstitial ad displays to comply with platform requirements and improve user experience.
Parameters
delay:number— 60 from default
bridge.advertisement.rewarded_state()
Monitor the state of the rewarded ad (loading, opened, closed, rewarded, failed) to manage the reward process.
bridge.advertisement.rewarded_placement()
Monitor the placement of the rewarded ad to manage the reward process.
bridge.advertisement.show_rewarded(placement: string)
Display a rewarded ad and provide incentives to players for watching the entire ad.
Parameters
placement:string
bridge.advertisement.is_advanced_banners_supported(): string
Check if the platform supports displaying advanced banner ads.
Returns
result:string
bridge.advertisement.advanced_banners_state()
Track the state of the advanced banners to manage ad display and user experience.
bridge.advertisement.show_advanced_banners(placement: string)
Display advanced banners at appropriate moments of the game.
Parameters
placement:string
bridge.advertisement.hide_advanced_banners()
Hide the currently displayed advanced banners when they are no longer needed.
bridge.advertisement.check_ad_block(on_success: function, on_failure: function)
Check if the ad blocker is enabled.
Parameters
on_success:function— function(_, bool)on_failure:function— function(_, error)
bridge.device.type(): string
Determine the type of device (mobile, tablet, desktop, tv) the game is being played on to adjust the game`s interface and performance settings.
Returns
result:string
bridge.player.is_authorization_supported(): boolean
Check if the platform supports player authorization to enable features that require user authentication, such as saving game progress or accessing social features.
Returns
result:boolean
bridge.player.is_authorized(): boolean
Verify if the player is currently authorized on the platform. This allows you to enable personalized features, such as saving high scores or providing user-specific content.
Returns
result:boolean
bridge.player.is_guest(): boolean
Check if the player is unauthorized or running as a guest.
Returns
result:boolean
bridge.player.id(): string | nil
Get the player’s unique ID on the platform to manage user-specific data and settings. Use this ID to track player progress, achievements, and purchases.
Returns
result:string | nil
bridge.player.name(): string | nil
Retrieve the player's name to personalize the game experience. Display the name in leaderboards, friend lists, or when sending notifications and messages.
Returns
result:string | nil
bridge.player.extra(): table
Get the extra information about player.
Returns
result:table
bridge.player.photos(): table
Get the count of player avatars available. Use this to manage and display user profile images effectively, such as showing the avatar in multiplayer lobbies or profile screens.
Returns
result:table
bridge.player.authorize(options: table, on_success: function, on_failure: function)
Authorize the player on the platform to access protected features and personalize the game experience. For example, prompting the player to log in to save their progress or unlock social sharing features.
Parameters
options:tableon_success:function— function()on_failure:function— function(_, error)
bridge.social.is_share_supported(): boolean
Check if the share functionality is supported on the platform.
Returns
result:boolean
bridge.social.share(id: string, on_success: function, on_failure: function)
Use this to allow players to share game content or achievements on social media platforms.
Parameters
id:string— The id of a social.shares entry declared in playgama-bridge-config.json.on_success:function— function(_)on_failure:function— function(_)
bridge.social.is_join_community_supported(): boolean
Check if the join community functionality is supported on the platform.
Returns
result:boolean
bridge.social.join_community(on_success: function, on_failure: function)
Invite players to join your community. The data is taken from social.joinCommunity in playgama-bridge-config.json.
Parameters
on_success:function— function(_)on_failure:function— function(_)
bridge.social.is_invite_friends_supported(): boolean
Check if the invite friends functionality is supported on the platform.
Returns
result:boolean
bridge.social.invite_friends(id: string, on_success: function, on_failure: function)
Allow players to invite their friends to play the game, helping to grow your player base organically.
Parameters
id:string— The id of a social.invites entry declared in playgama-bridge-config.json.on_success:function— function(_)on_failure:function— function(_)
bridge.social.is_create_post_supported(): boolean
Check if the create post functionality is supported on the platform.
Returns
result:boolean
bridge.social.create_post(id: string, payload: string, on_success: function, on_failure: function)
Use this to let players create posts about their achievements or updates directly from the game.
Parameters
id:string— The id of a social.posts entry declared in playgama-bridge-config.json.payload:string— Optional. The game's own string for this one post - a level, a seed, a challenge - handed back as bridge.platform.payload() when someone opens it. May be omitted, the callbacks then follow id.on_success:function— function(_)on_failure:function— function(_)
bridge.social.is_add_to_favorites_supported(): boolean
Check if the add to favorites functionality is supported on the platform.
Returns
result:boolean
bridge.social.add_to_favorites(on_success: function, on_failure: function)
Allow players to bookmark your game for easy access in the future.
Parameters
on_success:function— function(_)on_failure:function— function(_)
bridge.social.is_add_to_home_screen_supported(): boolean
Check if the add to home screen functionality is supported on the platform.
Returns
result:boolean
bridge.social.add_to_home_screen(on_success: function, on_failure: function)
Enable players to add a shortcut to your game on their home screen for quick access.
Parameters
on_success:function— function(_)on_failure:function— function(_)
bridge.social.is_rate_supported(): boolean
Check if the rate game functionality is supported on the platform.
Returns
result:boolean
bridge.social.rate(on_success: function, on_failure: function)
Encourage players to rate your game, providing valuable feedback and improving visibility.
Parameters
on_success:function— function(_)on_failure:function— function(_)
bridge.social.is_post_reward_supported(): boolean
Check if rewards around posts created with create_post are supported on the platform.
Returns
result:boolean
bridge.social.get_post_reward(on_success: function, on_failure: function)
Everything the player has coming from posts right now - the reward for the post the game was opened from and what the author earned from the players who came through their posts. Resolves to an empty array when there is nothing, so grant what you get and stay quiet otherwise. Each reward has the shape { id, amount, type }, where type is "visit" or "author".
Parameters
on_success:function— function(_, rewards)on_failure:function— function(_, error)
bridge.payments.is_supported(): boolean
Check if in-game purchases are supported to offer items or upgrades within the game.
Returns
result:boolean
bridge.payments.purchase(id: string, on_success: function, on_failure: function)
Allow players to buy items or upgrades in your game to enhance their gameplay experience.
Parameters
id:stringon_success:function— function(_, purchase)on_failure:function— function(_, error)
bridge.payments.consume_purchase(id: string, on_success: function, on_failure: function)
Consume purchased items, such as in-game currency, once they are used, to manage inventory and player progression.
Parameters
id:stringon_success:function— function(_, purchase)on_failure:function— function(_, error)
bridge.payments.get_catalog(on_success: function, on_failure: function)
Retrieve a list of all available in-game items that players can purchase to display in the game store.
Parameters
on_success:function— function(_, catalogItems)on_failure:function— function(_, error)
bridge.payments.get_purchases(on_success: function, on_failure: function)
Retrieve a list of items that the player has purchased to manage their inventory and provide access to purchased content.
Parameters
on_success:function— function(nil, purchases)on_failure:function— function(_, error)
bridge.achievements.unlock(id: string, on_success: function, on_failure: function)
Unlocks achievement for a player.
Parameters
id:stringon_success:function— function(_, result)on_failure:function— function(_, error)
bridge.achievements.get_achievements(on_success: function, on_failure: function)
Returns the achievement list in JSON.
Parameters
on_success:function— function(_, list)on_failure:function— function(_, error)
bridge.daily_rewards.get_rewards(on_success: function, on_failure: function)
Returns the configured ordered list of reward ids as a JSON string.
Parameters
on_success:function— function(_, rewards)on_failure:function— function(_, error)
bridge.daily_rewards.get_current_day(on_success: function, on_failure: function)
Returns the 0-based index of the reward the player is currently on.
Parameters
on_success:function— function(_, day). 0️⃣dayis 0-based; passed tobridgeunchanged.on_failure:function— function(_, error)
bridge.daily_rewards.get_current_reward(on_success: function, on_failure: function)
Returns the id of the reward claimable today, or nil when nothing can be claimed.
Parameters
on_success:function— function(_, reward)on_failure:function— function(_, error)
bridge.daily_rewards.claim_current_reward(on_success: function, on_failure: function)
Claims the reward available today. Calls on_success when claimed, on_failure otherwise.
Parameters
on_success:function— function(_)on_failure:function— function(_, error)
bridge.tasks.get_tasks(on_success: function, on_failure: function)
Returns every active task across all groups, with live progress, as a JSON string.
Parameters
on_success:function— function(_, tasks)on_failure:function— function(_, error)
bridge.tasks.add_progress(metric: string, amount: number, on_success: function, on_failure: function)
Advances every active target whose id equals the given metric, clamped to the target amount.
Parameters
metric:string— The metric id to advance.amount:number— The amount to add (defaults to 1).on_success:function— function(_)on_failure:function— function(_, error)
bridge.tasks.claim_reward(task_id: string, on_success: function, on_failure: function)
Claims a completed task's rewards. Calls on_success with true when claimed, false otherwise.
Parameters
task_id:string— The id of the task to claim.on_success:function— function(_, claimed)on_failure:function— function(_, error)
bridge.leaderboards.type(): string
Check the leaderboards type on the platform.
Returns
result:string
bridge.leaderboards.set_score(id: string, score: number, on_success: function, on_failure: function)
Submit the player's score to the leaderboard to update their rank and position.
Parameters
id:stringscore:numberon_success:function— function()on_failure:function— function(_, error)
bridge.leaderboards.get_entries(id: string, on_success: function, on_failure: function)
Retrieve entries from the leaderboard, including the player's rank and score, to display a comprehensive leaderboard.
Parameters
id:stringon_success:function— function(_, entries)on_failure:function— function(_, error)
bridge.leaderboards.show_native_popup(id: string, on_success: function, on_failure: function)
Show native popup leaderboard.
Parameters
id:stringon_success:function— function()on_failure:function— function(_, error)
bridge.remote_config.is_supported(): boolean
Check if remote configuration is supported to manage game settings without releasing updates.
Returns
result:boolean
bridge.remote_config.set_context(parameters: table)
Set dynamic game/player parameters used for config segmentation. Accumulates across calls; only used by platforms that support it.
Parameters
parameters:table
bridge.remote_config.get(on_success: function, on_failure: function)
Encourage players to rate your game, providing valuable feedback and improving visibility.
Parameters
on_success:function— function(_, data)on_failure:function— function(_)
bridge.notifications.is_supported(): boolean
Check if scheduling notifications is supported on the current platform.
Returns
result:boolean
bridge.notifications.schedule(notification: table, on_success: function, on_failure: function)
Schedule a notification. The notification table has the shape { id, title, description, delaySeconds, image, callToAction, payload }, where id is mapped to the platform value in the config file. The payload of the notification the game was launched from is available via bridge.platform.payload().
Parameters
notification:tableon_success:function— function(_)on_failure:function— function(_, error)
bridge.notifications.cancel(id: string, on_success: function, on_failure: function)
Cancel a previously scheduled notification with the given id.
Parameters
id:stringon_success:function— function(_)on_failure:function— function(_, error)
bridge.notifications.cancel_all(on_success: function, on_failure: function)
Cancel every notification scheduled by the game.
Parameters
on_success:function— function(_)on_failure:function— function(_, error)
bridge.analytics.send(event_name: string, data: table)
Send a game event. The event name and the data are entirely up to the game — they are never matched against the SDK's own event names.
Parameters
event_name:string— The event name.data:table— Optional event payload (may be omitted).
bridge.multiplayer.on(event_name: string, callback: function)
Subscribe to multiplayer events. Use the bridge.EVENT_NAME.MULTIPLAYER_* constants. The callback receives: multiplayer_state_changed - state string (see bridge.MULTIPLAYER_STATE) multiplayer_room_left - reason string (see bridge.ROOM_LEAVE_REASON) multiplayer_room_updated - room table multiplayer_player_joined - player table multiplayer_player_left - player table multiplayer_player_updated - player table multiplayer_host_changed - new host player table or nil multiplayer_message_received - message table { type, data, from } multiplayer_sync_state_received - world table (see set_sync_state)
Parameters
event_name:stringcallback:function— function(_, data)
bridge.multiplayer.is_supported(): boolean
Check if multiplayer is supported on the current platform.
Returns
result:boolean
bridge.multiplayer.state(): string
Connection state - "disconnected", "connecting", "connected" or "reconnecting" (see bridge.MULTIPLAYER_STATE).
Returns
result:string
bridge.multiplayer.is_in_room(): boolean
Check if the player is in a room (connected or reconnecting).
Returns
result:boolean
bridge.multiplayer.is_host(): boolean
Check if the local player is the room host.
Returns
result:boolean
bridge.multiplayer.player_id(): string | nil
The local player id in the room, nil outside of a room.
Returns
result:string | nil
bridge.multiplayer.host_id(): string | nil
The room host player id, nil outside of a room.
Returns
result:string | nil
bridge.multiplayer.room_id(): string | nil
The room code other players type to join, nil outside of a room.
Returns
result:string | nil
bridge.multiplayer.region(): string | nil
Region of the next created or matched room and of get_rooms, e.g. "eu". nil until set_region, get_regions or the first room call.
Returns
result:string | nil
bridge.multiplayer.room(): table | nil
The current room with the shape { id, type, maxPlayers, isOpen, isVisible, hostId, properties }, nil outside of a room.
Returns
result:table | nil
bridge.multiplayer.players(): table
The players in the current room, each with the shape { id, name, isHost, isConnected, properties }. Empty outside of a room.
Returns
result:table
bridge.multiplayer.is_invite_supported(): boolean
Check if the platform can share an invite link to the current room, see invite_to_room.
Returns
result:boolean
bridge.multiplayer.launch_room_id(): string | nil
The room code from the invite link the game was opened with, pass it to join_room. nil when there is none or once the player has entered any room.
Returns
result:string | nil
bridge.multiplayer.sync_state(): table
The last world - set with set_sync_state or received. Empty when there is none.
Returns
result:table
bridge.multiplayer.create_room(options: table, on_success: function, on_failure: function)
Create a room and enter it as the host. A hidden room (the default) is for friends - only players the room code was shared with can join.
Parameters
options:table— Optional (may be omitted) { maxPlayers, isVisible (default false), isOpen (default true), filter (lets quick match and filtered room lists find a visible room), properties, playerName, playerProperties, syncState (true or { updatesPerSecond }, see set_sync_state) }.on_success:function— function(_, room_id)on_failure:function— function(_, error), error is the code, e.g. MULTIPLAYER_ROOM_FULL
bridge.multiplayer.join_room(room_id: string, options: table, on_success: function, on_failure: function)
Join a room by its code.
Parameters
room_id:stringoptions:table— Optional (may be omitted) { playerName, playerProperties, syncState (true or { updatesPerSecond }, see set_sync_state) }.on_success:function— function(_)on_failure:function— function(_, error), error is the code, e.g. MULTIPLAYER_ROOM_FULL
bridge.multiplayer.join_or_create_room(options: table, on_success: function, on_failure: function)
Quick match - enter a visible room with the same maxPlayers and exactly the same filter, or create a visible one (its creator becomes the host). A created room also gets the filter values in its properties.
Parameters
options:table— Optional (may be omitted) { maxPlayers, filter, properties, playerName, playerProperties, syncState (true or { updatesPerSecond }, see set_sync_state) }.on_success:function— function(_, room_id)on_failure:function— function(_, error), error is the code, e.g. MULTIPLAYER_ROOM_FULL
bridge.multiplayer.get_rooms(options: table, on_success: function, on_failure: function)
Get visible open rooms with a free seat, for a room browser. Each room has the shape { id, type, maxPlayers, playerCount, filter, properties }.
Parameters
options:table— Optional (may be omitted) { filter (only rooms created with exactly this filter), maxPlayers, limit }.on_success:function— function(_, rooms)on_failure:function— function(_, error), error is the code, e.g. MULTIPLAYER_ROOM_FULL
bridge.multiplayer.get_regions(on_success: function, on_failure: function)
Get region ids for a region picker, e.g. { "eu", "us", "ap" }. Also sets region to the default one if it is still unknown.
Parameters
on_success:function— function(_, regions)on_failure:function— function(_, error), error is the code, e.g. MULTIPLAYER_NOT_SUPPORTED
bridge.multiplayer.set_region(region: string)
Set the region (an id from get_regions) of the next created or matched room and of get_rooms. The current room stays where it is; join_room by code always enters the region of the code.
Parameters
region:string
bridge.multiplayer.invite_to_room(options: table, on_success: function, on_failure: function)
Ask the platform to share a link to the current room. Whoever opens it starts the game with the room code in launch_room_id.
Parameters
options:table— Optional (may be omitted) { text, image, ... }.on_success:function— function(_, result)on_failure:function— function(_, error), error is the code, e.g. MULTIPLAYER_ROOM_FULL
bridge.multiplayer.leave_room()
Leave the current room.
bridge.multiplayer.set_room_open(is_open: boolean)
Host only. Stop (or resume) accepting new players, e.g. once the match starts.
Parameters
is_open:boolean
bridge.multiplayer.set_room_visible(is_visible: boolean)
Host only. Show (or hide) the room in the room list and matchmaking.
Parameters
is_visible:boolean
bridge.multiplayer.set_room_properties(properties: table)
Host only. Update the room properties - keys are merged, a json.null value removes the key.
Parameters
properties:table
bridge.multiplayer.set_player_properties(properties: table)
Update the local player properties - keys are merged, a json.null value removes the key.
Parameters
properties:table
bridge.multiplayer.send(message_type: string, data: table | string | number | boolean | nil, options: table)
Send a message to other players in the room. It arrives in the multiplayer_message_received event as { type, data, from }.
Parameters
message_type:stringdata:table | string | number | boolean | nil— Optional message data (any JSON-compatible value).options:table— Optional { to }, where to is "all", "others" (default), "host" (see bridge.MULTIPLAYER_TARGET), a player id or a table of player ids.
bridge.multiplayer.set_sync_state(state: table)
Set the local game world. When the room is entered with syncState, the host sends its world to the other players up to updatesPerSecond times a second (1-10, default 10) and they get it in the multiplayer_sync_state_received event. The server keeps the last world - a new host gets it in the same event and goes on from it. Works outside a room too, e.g. to set the starting world before create_room. Reset to an empty table when the room is left.
Parameters
state:table— The whole world (JSON-compatible), up to 64 KB.