| name | integration |
| description | Use this skill when working with Playgama Bridge SDK for Defold games. Activates for game development involving cross-platform publishing, advertisements, in-app purchases, leaderboards, or social features using Playgama Bridge in Defold/Lua. |
Playgama Bridge SDK Integration for Defold
Playgama Bridge is a cross-platform SDK for publishing Defold HTML5 games across 20+ platforms including Playgama, YouTube, Yandex Games, Crazy Games, Poki, Facebook, Telegram, Xiaomi, and more.
Installation
- Copy the
Source code.zip link from the GitHub releases page
- Add it as a dependency in your project settings (
game.project file)
- Select
Project -> Fetch Libraries to download the SDK
Configuration
- Download the
playgama-bridge-config.json file from the GitHub releases
- Place it in the
res/web folder
- Ensure the
/res directory is added to Bundle Resources in project settings
- Configure game identifiers and in-app purchases in the config file
HTML5 Export
When building for HTML5, select the appropriate index template provided by the SDK to ensure proper initialization.
Initialization
Once the game is loaded, the plugin is already initialized. No additional actions are required. Access all modules through the bridge module:
local bridge = require("bridge.bridge")
bridge.platform
bridge.player
bridge.device
bridge.storage
bridge.advertisement
bridge.payments
bridge.leaderboards
bridge.social
bridge.achievements
After game is fully loaded, send the game ready message:
bridge.platform.send_message("game_ready")
Device
local bridge = require("bridge.bridge")
local device_type = bridge.device.type()
Platform
local bridge = require("bridge.bridge")
local platform_id = bridge.platform.id()
local language = bridge.platform.language()
local tld = bridge.platform.tld()
local payload = bridge.platform.payload()
Server Time
local bridge = require("bridge.bridge")
function init(self)
bridge.platform.get_server_time(function (_, data)
print("Server time: ", data)
end, function ()
end)
end
Platform Messages
bridge.platform.send_message("game_ready")
bridge.platform.send_message("gameplay_started")
bridge.platform.send_message("gameplay_stopped")
bridge.platform.send_message("in_game_loading_started")
bridge.platform.send_message("in_game_loading_stopped")
bridge.platform.send_message("player_got_achievement")
Audio State Listener
local bridge = require("bridge.bridge")
function init(self)
bridge.platform.on("audio_state_changed", function (_, is_enabled)
print("Is audio enabled: ", is_enabled)
end)
end
Pause State Listener
local bridge = require("bridge.bridge")
function init(self)
bridge.platform.on("pause_state_changed", function (_, is_paused)
print("Is paused: ", is_paused)
end)
end
Player
local bridge = require("bridge.bridge")
local is_auth_supported = bridge.player.is_authorization_supported()
local is_authorized = bridge.player.is_authorized()
local player_id = bridge.player.id()
local player_name = bridge.player.name()
local photos = bridge.player.photos()
local extra = bridge.player.extra()
Authorization
local bridge = require("bridge.bridge")
function init(self)
local options = {}
bridge.player.authorize(
options,
function ()
print("Authorized: ", bridge.player.id())
end,
function ()
print("Authorization failed")
end)
end
Storage
Get Data
local bridge = require("bridge.bridge")
function init(self)
bridge.storage.get(
{ "coins", "level" },
function (_, data)
if data.coins then
print("Coins: ", data.coins)
end
if data.level then
print("Level: ", data.level)
end
end,
function ()
end
)
end
Set Data
local bridge = require("bridge.bridge")
function init(self)
bridge.storage.set(
{ coins = 42, level = "dungeon" },
function (_)
print("Data saved")
end,
function (_)
end
)
end
Delete Data
local bridge = require("bridge.bridge")
function init(self)
bridge.storage.delete(
{ "coins", "level" },
function ()
end,
function ()
end
)
end
Banner Ads
local bridge = require("bridge.bridge")
local is_supported = bridge.advertisement.is_banner_supported()
function init(self)
local position = "bottom"
local placement = "menu"
bridge.advertisement.show_banner(position, placement)
end
bridge.advertisement.hide_banner()
Banner State
local bridge = require("bridge.bridge")
function init(self)
bridge.advertisement.on("banner_state_changed", function (_, state)
print("Banner state changed: ", state)
end)
end
Interstitial Ads
local bridge = require("bridge.bridge")
local is_supported = bridge.advertisement.is_interstitial_supported()
local state = bridge.advertisement.interstitial_state()
local delay = bridge.advertisement.minimum_delay_between_interstitial()
bridge.advertisement.set_minimum_delay_between_interstitial(30)
local placement = "level_complete"
bridge.advertisement.show_interstitial(placement)
Interstitial State
local bridge = require("bridge.bridge")
function init(self)
bridge.advertisement.on("interstitial_state_changed", function (_, state)
print("Interstitial state changed: ", state)
if state == "opened" then
elseif state == "closed" or state == "failed" then
end
end)
end
Note: Do not call show_interstitial() at game start. On platforms where this is allowed, ads will be shown automatically.
Rewarded Ads
local bridge = require("bridge.bridge")
local is_supported = bridge.advertisement.is_rewarded_supported()
local state = bridge.advertisement.rewarded_state()
local placement = bridge.advertisement.rewarded_placement()
local placement = "double_coins"
bridge.advertisement.show_rewarded(placement)
Rewarded State
local bridge = require("bridge.bridge")
function init(self)
bridge.advertisement.on("rewarded_state_changed", function (_, state)
print("Rewarded state changed: ", state)
if state == "opened" then
elseif state == "rewarded" then
elseif state == "closed" or state == "failed" then
end
end)
end
Important: Only grant rewards when state is rewarded.
In-App Purchases
local bridge = require("bridge.bridge")
local is_supported = bridge.payments.is_supported()
Purchase Item
local bridge = require("bridge.bridge")
function init(self)
local id = "coins_100"
bridge.payments.purchase(id, function (_, purchase)
print("Purchased: ", purchase.id)
end, function (_, error)
end)
end
Consume Purchase
local bridge = require("bridge.bridge")
function init(self)
local id = "coins_100"
bridge.payments.consume_purchase(id, function (_, purchase)
end, function ()
end)
end
Get Catalog
local bridge = require("bridge.bridge")
function init(self)
bridge.payments.get_catalog(function (_, catalog)
for key, value in pairs(catalog) do
local id = value.id
local price = value.price
local priceCurrencyCode = value.priceCurrencyCode
local priceValue = value.priceValue
print("Product: ", id, " Price: ", price)
end
end, function ()
end)
end
Get Purchases
local bridge = require("bridge.bridge")
function init(self)
bridge.payments.get_purchases(function (_, purchases)
for key, value in pairs(purchases) do
local id = value.id
print("Owned: ", id)
end
end, function ()
end)
end
Leaderboards
local bridge = require("bridge.bridge")
local leaderboard_type = bridge.leaderboards.type
Set Score
local bridge = require("bridge.bridge")
function init(self)
local leaderboardId = "high_score"
local score = 1000
bridge.leaderboards.set_score(leaderboardId, score, function ()
end, function ()
end)
end
Get Entries
Works only when bridge.leaderboards.type equals in_game:
local bridge = require("bridge.bridge")
function init(self)
local leaderboardId = "high_score"
local options = {}
bridge.leaderboards.get_entries(options, function (_, data)
for key, value in pairs(data) do
print("ID: ", value.id)
print("Name: ", value.name)
print("Photo: ", value.photo)
print("Score: ", value.score)
print("Rank: ", value.rank)
end
end, function ()
end)
end
Show Native Popup
Works only when bridge.leaderboards.type equals native_popup:
local bridge = require("bridge.bridge")
function init(self)
local leaderboardId = "high_score"
bridge.leaderboards.show_native_popup(leaderboardId, function ()
end, function ()
end)
end
Social Features
Share
local bridge = require("bridge.bridge")
function init(self)
local is_supported = bridge.social.is_share_supported()
local options = {
vk = {
link = "YOUR_LINK"
},
facebook = {
image = "A base64 encoded image to be shared",
text = "A text message to be shared."
},
msn = {
title = "A title to display",
image = "A base64 encoded image or image URL to be shared",
text = "A text message to be shared."
}
}
bridge.social.share(options, function ()
end, function ()
end)
end
Invite Friends
local bridge = require("bridge.bridge")
function init(self)
local options = {
vk = {
text = "Hello World!"
},
facebook = {
image = "A base64 encoded image to be shared",
text = "A text message"
}
}
bridge.social.invite_friends(options, function ()
end, function ()
end)
end
Join Community
local bridge = require("bridge.bridge")
function init(self)
local options = {
vk = {
groupId = "YOUR_GROUP_ID"
},
ok = {
groupId = "YOUR_GROUP_ID"
},
facebook = {
isPage = true
}
}
bridge.social.join_community(options, function ()
end, function ()
end)
end
Create Post
local bridge = require("bridge.bridge")
function init(self)
local options = {
ok = {
media = {
{
type = "text",
text = "Hello World!"
},
{
type = "link",
url = "https://apiok.ru"
},
{
type = "poll",
question = "Do you like our game?",
answers = {
{ text = "Yes" },
{ text = "No" }
},
options = "SingleChoice,AnonymousVoting"
}
}
}
}
bridge.social.create_post(options, function ()
end, function ()
end)
end
Add to Favorites
bridge.social.add_to_favorites(function ()
end, function ()
end)
Add to Home Screen
bridge.social.add_to_home_screen(function ()
end, function ()
end)
Rate Game
bridge.social.rate(function ()
end, function ()
end)
Achievements
local bridge = require("bridge.bridge")
local is_supported = bridge.achievements.is_supported()
local is_get_list_supported = bridge.achievements.is_get_list_supported()
local is_native_popup_supported = bridge.achievements.is_native_popup_supported()
Unlock Achievement
local bridge = require("bridge.bridge")
function init(self)
local options = {
y8 = {
achievement = "ACHIEVEMENT_NAME",
achievementkey = "ACHIEVEMENT_KEY"
},
lagged = {
achievement = "ACHIEVEMENT_ID"
}
}
bridge.achievements.unlock(options, function ()
end, function ()
end)
end
Get List
local bridge = require("bridge.bridge")
function init(self)
local options = {}
bridge.achievements.get_list(options, function (_, data)
for key, value in pairs(data) do
print("Achievement: ", value)
end
end, function ()
end)
end
Show Native Popup
local bridge = require("bridge.bridge")
function init(self)
local options = {}
bridge.achievements.show_native_popup(options, function ()
end, function ()
end)
end
Best Practices
- Always call
bridge.platform.send_message("game_ready") when game is fully loaded
- Subscribe to
audio_state_changed and mute/unmute game audio accordingly
- Subscribe to
pause_state_changed and pause/resume game accordingly
- Show ads at natural breakpoints (level transitions, player death), not during gameplay
- Check
is_supported methods before using platform-specific features
- Grant rewards only when rewarded ad state is
rewarded
- Use platform-specific options for social features based on
bridge.platform.id()
- Wait for storage callbacks before making sequential storage operations
- Do not call
show_interstitial() at game start - it will be shown automatically where allowed