Trigger API Reference\DCEI Functions\Service

string GetTranslationText(string key, Dictionary<string, object> parameters)

string GetTranslationText(string key, Dictionary<string, object> parameters)

Description


Returns a localized string from localization data using the specified key. Additional parameters can be used for replacement text.

You can change what language is used in the editor in Play Settings.

Parameters

Example Usage

-- key: "data/hero/ice_mage/skill01/description"
-- english text: "Slows nearby enemies by {[x]} for {[y]} seconds."
-- logged text: "Slows nearby enemies by 50% for 3 seconds."

local text = DCEI.GetTranslationText("data/hero/ice_mage/skill01/description", { x = "50%", y = "3" })
DCEI.LogMessage(text)

void SetTranslationText(string key, string text)

void SetTranslationText(string key, string text)

Description


Manually inputs translation text into the given key. You can put {[]} around variables in your text to allow you to easily replace them when using GetTranslationText.

Parameters

Example Usage

DCEI.SetTranslationText("data/hero/ice_mage/skill01/description", "Slows nearby enemies by {[x]} for {[y]} seconds.")
local text = DCEI.GetTranslationText("data/hero/ice_mage/skill01/description", { x = "50%", y = "3" })

-- text: "Slows nearby enemies by 50% for 3 seconds."
DCEI.LogMessage(text)

bool IsAdsReady()

bool IsAdsReady()

Description


Returns true if ads are ready.

Example Usage

local ads_ready = DCEI.IsAdsReady()
if ads_ready then
    DCEI.ShowAds(ResolveAds)
end

void ShowAds(TypedCallback<bool> callback, bool fallbackToUnityAds = False)

void ShowAds(TypedCallback<bool> callback, bool fallbackToUnityAds = False)

Description


Attempts to show ads in published mobile and web games. If successful, the first parameter of the callback function will return true. This can be simulated in Play Settings.

Parameters

Callback Parameters

Example Usage

function ResolveAds(success)
  if success then
    -- deliver ad rewards to player
  else
    -- show error message for player
  end
end

DCEI.ShowAds(ResolveAds)

bool IsOnline()

bool IsOnline()

Description


Returns true if the user currently has internet access. This can be simulated in Play Settings.

Example Usage

local is_online = DCEI.IsOnline()
if is_online then
    DCEI.LogMessage(tostring(is_online))
end

bool IsDev()

bool IsDev()

Description


Returns true if the user currently has developer access. This can be simulated in Play Settings.

Example Usage

local is_dev = DCEI.IsDev()
if is_dev then
    DCEI.LogMessage(tostring(is_dev))
end

bool IsGooglePlayGamesOnPc()

bool IsGooglePlayGamesOnPc()

Description


Returns true if the game is played through Google Play Games on PC platform.

Example Usage

if DCEI.IsGooglePlayGamesOnPc() then
    DCEI.LogMessage("AY YO! I'm playing Google Play Games on PC over 'ere!")
end

void GetSaveDataHistory(int count, TypedCallback<object> callback)

void GetSaveDataHistory(int count, TypedCallback<object> callback)

Description


Attempts to fetch the player's save history. If successful, the callback will return with the save history as a table as its first parameter.

Parameters

Callback Parameters

Example Usage

local function ResultCallback(result)
    if result then
        for _, save in ipairs(result.saves) do
            DCEI.LogMessage("Save data timestamp:" .. save.time)
        end       
    end
end
DCEI.Settings.GetSaveDataHistory(count, ResultCallback)

void ResetSavedMapDataByIndex(int index)

void ResetSavedMapDataByIndex(int index)

Description


Attempts to reset the saved map data at the given index.

Parameters

Example Usage

function LoadBackupSaveDataPriority()
    if not loading_backup_savedata then
        loading_backup_savedata = true
        local callback_func = function(result)
            if result then
                local index = 1
                local max_wave = 0
                if result.saves then
                    for id, entry in ipairs(result.saves) do
                        -- DCEI.LogMessage("Save data time:"..entry.time)
                        if entry.save and entry.save.max_wave then
                            -- DCEI.LogMessage("Max wave:"..entry.save.max_wave)
                            if entry.save.max_wave > max_wave then
                                index = id
                                max_wave = entry.save.max_wave
                            end
                        end
                    end
                    if max_wave > 0 then
                        -- DCEI.LogMessage("Restore wave:"..max_wave.."  id: "..index)
                        DCEI.TriggerAddTimerEventElapsed(function()
                            DCEI.ResetSavedMapDataByIndex(index)
                        end, 0, true, true)
                    end
                end
            end
        end
        DCEI.GetSaveDataHistory(10, callback_func)
    end
end

void GetMail(TypedCallback<object> callback, bool forceFetch)

void GetMail(TypedCallback<object> callback, bool forceFetch)

Description


Attempts to fetch the player's mail. If successful, the callback will return with the save history as a table as its first parameter.

Parameters

Callback Parameters

Example Usage

function MailHandler(result)
    --Handle mail
end
DCEI.GetMail(MailHandler, false)

void DeleteMail(int instanceId)

void DeleteMail(int instanceId)

Description


Attempts to delete the mail with the given ID.

Parameters

Example Usage

local layout = GMUI.Layout.New({
    parent = DCEI.GetUiRootFrame(),
    name = "Standard/Button/Button",
})
DCEI.SetOnClickCallback(layout.Button, function()
    DCEI.DeleteMail(1)
end)

void DeleteUserAccount(TypedCallback callback)

void DeleteUserAccount(TypedCallback callback)

Description


Intended to be used on iOS to comply with their App Store requirements. Removes all user information and stops the game from being played further.

Parameters

Example Usage

if DCEI.Platform == "IPhonePlayer" then
    local button = DCEI.CreateButtonFrame(DCEI.GetUiRootFrame())
    DCEI.SetFrameSize(button, 120, 50)

    DCEI.SetOnClickCallback(button, function()
        DCEI.DeleteUserAccount(function() DCEI.LogMessage("☠️") end)
    end)
end

bool AreNotificationsEnabled()

bool AreNotificationsEnabled()

Description


Checks if the user has mobile notifications enabled for this game/app.

Example Usage

local status = DCEI.AreNotificationsEnabled()
if not status then
    DCEI.ShowFeedbackMessage("Please enable notifications")
    DCEI.OpenNotificationSettings()
end

void OpenNotificationSettings()

void OpenNotificationSettings()

Description


Open users notification settings to prompt them to enable notifications for this app. Used with DCEI.AreNotificationsEnabled()

Example Usage

local status = DCEI.AreNotificationsEnabled()
if not status then
    DCEI.ShowFeedbackMessage("Please enable notifications")
    DCEI.OpenNotificationSettings()
end

int ScheduleNotification(string title, string body, double timeInSeconds)

int ScheduleNotification(string title, string body, double timeInSeconds)

Description


Schedules a notification and returns the ID of said notification. Only works on mobile.

Parameters

Example Usage

-- Schedule a notification after 2 minutes
local title = "Title"
local body = "Notification"
local timeInSeconds = 120

local id = DCEI.ScheduleNotification(title, body, timeInSeconds)

void CancelNotification(int id)

void CancelNotification(int id)

Description


Cancels a notification from the given id. Only works on mobile.

Parameters

Example Usage

-- Schedule a notification after 2 minutes
local title = "Title"
local body = "Notification"
local timeInSeconds = 120

local id = DCEI.ScheduleNotification(title, body, timeInSeconds)

---
DCEI.CancelNotification(id)

object GetLastNotificationId()

object GetLastNotificationId()

Description


Returns the last notification ID. Only works on mobile.

Example Usage

local last_notif_id = DCEI.GetLastNotificationId()
DCEI.LogMessage(last_notif_id)

void ShowSendSMS(int platform)

void ShowSendSMS(int platform)

Description


Shows the SMS invitation screen. Only works on mobile or web builds.

Parameters

Example Usage

local layout = GMUI.Layout.New({
    parent = DCEI.GetUiRootFrame(),
    name = "Standard/Button/Button",
})
DCEI.SetOnClickCallback(layout.Button, function()
    DCEI.ShowSendSMS(1)
end)

void RestartApplication()

void RestartApplication()

Description


Restarts the application. Only works on mobile.

Example Usage

local layout = GMUI.Layout.New({
    parent = DCEI.GetUiRootFrame(),
    name = "Standard/Button/Button",
})
DCEI.SetOnClickCallback(layout.Button, function()
    DCEI.RestartApplication()
end)

void QuitApplication()

void QuitApplication()

Description


Closes the application. Works in the editor, unlike RestartApplication().

Example Usage

local layout = GMUI.Layout.New({
    parent = DCEI.GetUiRootFrame(),
    name = "Standard/Button/Button",
})
DCEI.SetOnClickCallback(layout.Button, function()
    DCEI.QuitApplication()
end)

void SetResolution(int width, int height, FullScreenMode mode)

void SetResolution(int width, int height, FullScreenMode mode)

Description

Parameters

Example Usage

DCEI.SetResolution(1000, 500, "Windowed")
-- Logs after a timer so the game has time to update.
DCEI.TriggerAddTimerEventElapsed(function()
    local resolution = DCEI.GetCurrentResolution()
    DCEI.LogMessage("Width: " .. resolution.width)
    DCEI.LogMessage("Height: " .. resolution.height)
    DCEI.LogMessage("Mode: " .. resolution.mode)
end, 0)

FullScreenMode

object GetCurrentResolution()

object GetCurrentResolution()

Description


Gets the current screen resolution of the game. Returns a Lua table in the form of {width = int, height = int, mode = string}.

Example Usage

DCEI.SetResolution(1000, 500, "Windowed")
-- Logs after a timer so the game has time to update.
DCEI.TriggerAddTimerEventElapsed(function()
    local resolution = DCEI.GetCurrentResolution()
    DCEI.LogMessage("Width: " .. resolution.width)
    DCEI.LogMessage("Height: " .. resolution.height)
    DCEI.LogMessage("Mode: " .. resolution.mode)
end, 0)

FullScreenMode

object GetSupportedResolutions()

object GetSupportedResolutions()

Description


Returns a table of supported resolutions. The format of each resolution entry is {{width = 640, height = 480}, {width = 720, height = 400}, etc.}. If multiple monitors are detected, the function will include the same resolution entry for each supported screen.
For example, {{width = 1760, height = 900}, {width = 1760, height = 900}, {width = 1920, height = 1080}} indicates support for two monitors with resolutions 1760x900 and one monitor with resolution 1920x1080."

Example Usage

local resolutions = DCEI.GetSupportedResolutions()

-- Print the supported resolutions
for i, resolution in ipairs(resolutions) do
    DCEI.LogMessage("Resolution " .. i .. ": " .. resolution.width .. "x" .. resolution.height)
end

void OpenUrl(string url)

void OpenUrl(string url)

Description


Opens a web url in the user's default browser.

Parameters

Example Usage

local layout = GMUI.Layout.New({
    parent = DCEI.GetUiRootFrame(),
    name = "Standard/Button/Button",
})
DCEI.SetOnClickCallback(layout.Button, function()
    DCEI.OpenUrl("https://wiki.editor.funovus.com/master/Trigger-API-Reference-DCEI-Functions-Service#openurl-1")
end)

void ShareText(string text)

void ShareText(string text)

Description


Share some text with other applications. It's up to the other applications to decide how to use the shared text.

Parameters

Example Usage

function layout:ShareText()
    local text = "Save social media"
    local hashtag = "#SuperMediaHero"
    local url = "https://www.funovus.com/games/super-media-hero"
    local share_text = text .. " " .. tostring(self.code) .. " " .. hashtag .. " " .. url
    DCEI.ShareText(share_text)
end

void RequestAppStoreReview()

void RequestAppStoreReview()

Description


Requests an app store review. Only works on iOS devices.

Example Usage

local button_layout = GMUI.Layout.New({
    parent = DCEI.GetUiRootFrame(),
    name = "Standard/Button/Button",
})

DCEI.SetOnClickCallback(button_layout.Button, function()
    DCEI.RequestAppStoreReview()
end)

void RequestInAppReview(Action successCallback, Action failureCallback)

void RequestInAppReview(Action successCallback, Action failureCallback)

Description


Requests an in-app review. Only works on iOS devices.

Parameters

Example Usage

local button_layout = GMUI.Layout.New({
    parent = DCEI.GetUiRootFrame(),
    name = "Standard/Button/Button",
})

DCEI.SetOnClickCallback(button_layout.Button, function()
    DCEI.RequestInAppReview(SuccessCallback, FailureCallback)
end)

void GetServerTime(TypedCallback<int> callback)

void GetServerTime(TypedCallback<int> callback)

Description


Attempts to return the server time as the first parameter of a callback function. If it fails, returns 0.

Parameters

Callback Parameters

Example Usage

local function ResultCallback( time_stamp )
  if time_stamp and time_stamp ~= 0 then
    -- retrieving server time was successful and time_stamp will be the current unix timestamp
  else
    -- connection failed/timeout
  end
end

DCEI.GetServerTime( ResultCallback )

Note that in editor mode, DCEI.GetServerTime() will always return the local os time, using a delay to simulate network latency.

In production, time_stamp can fail or take some time to return and you must account for these cases (player has no internet or is in airplane mode, most games display a "cannot connect to server" message when an offline player tries to do something that requires internet).

Ideally you only need to successfully call DCEI.GetServerTime() once (or once per day).

Say if a daily rewards calendar resets at midnight PST, that you only need to check again after midnight. For other things just use os time or keep track of in-game time.

void GetServerData(TypedCallback<object> callback)

void GetServerData(TypedCallback<object> callback)

Description


Fetches from the server a list of key/value pairs configured by designers. Its primary use case is to let designers configure which client version is supported and inform users on old versions to upgrade. To configure these values, make changes to a configs git repo (ask engineers to gain access).

Parameters

Callback Parameters

Example Usage

local function ResultCallback( data )
  if data then
    -- retrieving server data was successful and `data` will be the server data config table
  else
    -- connection failed/timeout
  end
end

DCEI.GetServerData( ResultCallback )

void CallServerFunction(string name, string request, TypedCallback<object> callback)

void CallServerFunction(string name, string request, TypedCallback<object> callback)

Description


This enables you to call a lua function stored on the server, passing it some data and getting data in return. The primary use case is to combat cheating and hacking especially with PvP game modes. This requires setting up the server script on the backend for an already published game project (like Wild Castle). Most likely, designers would not be utilizing this feature without first discussing the application with the engineering team.

Parameters

Callback Parameters

Example Usage


https://platform.wildsky.dev/arcade/game/789

local json = require("json")

local text = DCEI.CreateTextFrame(DCEI.GetUiRootFrame())
DCEI.SetTextFrameText(text, "test server function")

local request = json.encode({value = 1})
DCEI.CallServerFunction("IncreaseByOne", request, function(response)
    if #response == 0 then
        error("IncreaseByOne has failed.")
    end
    local result = json.decode(response)
    DCEI.SetTextFrameText(text, "server result: " .. result.value)
end)

string GetRemoteConfigValue(string name)

string GetRemoteConfigValue(string name)

Description


(Internal) You can configure a set of key/value pairs in Firebase Remote Config and use a new trigger API DCEI.GetRemoteConfigValue(name) to fetch the value. The benefit of using Firebase Remote Config is that it allows you to change the value remotely, set different values for different user groups, and A/B test different values without rebuilding the game. For more use cases, see: https://firebase.google.com/docs/remote-config/use-cases

This new API provides a superset of features compared to GetServerData. We can deprecate GetServerData.

Parameters

Example Usage

-- Note: Internal use API, look to existing game code base for better example usage, if any. 
local value = DCEI.GetRemoteConfigValue("AB_test_gems")
DCEI.LogError(tostring(value))

string GetUserId()

string GetUserId()

Description


Returns the player's internal user ID. This can be simulated in Play Settings.

Example Usage

local user_id = DCEI.GetUserId()
DCEI.LogMessage(user_id)

string GetUserName()

string GetUserName()

Description


Returns the player's username.

Example Usage

local user_name = DCEI.GetUserName()
DCEI.LogMessage(user_name)

string GetUserTag()

string GetUserTag()

Description


Returns the player's tag.

Example Usage

local user_tag = DCEI.GetUserTag()
DCEI.LogMessage(user_tag)

void GetReferralCode(TypedCallback<object> callback)

void GetReferralCode(TypedCallback<object> callback)

Description


Get the referral code of the current player. If successful, the callback will be called with a Lua table {code = string, count = number} where code is the referral code and count is the number of players who have used the referral code. The count value should be persisted in the save data. Rewards should be given the player when the server returned count value is larger than the one in save data.

Parameters

Callback Parameters

Example Usage

function AttemptFetchReferralCode()
    DCEI.GetReferralCode(function(data)
        DCEI.LogMessage("Code:" .. data.code)
        DCEI.LogMessage("Count:" .. data.count)
    end)
end

void UseReferralCode(string code, TypedCallback<object> callback)

void UseReferralCode(string code, TypedCallback<object> callback)

Description


Use a referral code from another player. If successful, the callback will be called with a Lua table {code = string, count = number}. The returned referral code should be persisted in save data along with the referral rewards.

Parameters

Callback Parameters

Example Usage

function AttemptFetchReferralCode()
    local stored_code 
    DCEI.GetReferralCode(function(data)
        local stored_code =  data.code
    end)

    DCEI.UseReferralCode(stored_code, function(data)
        DCEI.LogMessage("Code:" .. data.code)
        DCEI.LogMessage("Count:" .. data.count)
    end)
end

void GenerateDeepLink(string payload, TypedCallback<string> callback)

Description


Generates a deep link from the given payload data.

Parameters

Callback Parameters

Example Usage

-- Placeholder example
DCEI.GenerateDeepLink("", function(url)
    DCEI.LogMessage(url)
end)

void TriggerAddDeepLinkEvent(TypedCallback<string> callback)

void TriggerAddDeepLinkEvent(TypedCallback<string> callback)

Description


If the game is opened via a deep link, the callback will be called with the payload string that's originally used to create the deep link.
Depending on if the game is installed, clicking on a deep link either opens the game or redirects the user to the store page. You can use it to generate invitation links and give rewards to invited players.
Note that deep link APIs only work on mobile devices and require external service setup before use. Ask the engineers if you want to use them in your game.

Parameters

Callback Parameters

Example Usage

-- Placeholder example
DCEI.TriggerAddDeepLinkEvent(function(payload)
    DCEI.LogMessage(payload)
end)

void GetLeaderBoardScore(string type, TypedCallback<object> callback)

void GetLeaderBoardScore(string type, TypedCallback<object> callback)

Description


Attempts to fetch the leaderboard score for the player as the first parameter in the callback function.

Parameters

Callback Parameters

Example Usage

DCEI.GetLeaderBoardScore("type1", function(result)
    DCEI.LogMessage(string.format("Group: %i\nPayload: %s\nRank: %i\nScore: %i,\nUUID: %s\n", result.group, result.payload, result.rank, result.score, result.uuid) .. os.date("%x", result.time))
end)

void GetLeaderBoardScoreList(string type, int skip, int limit, TypedCallback<object> callback)

void GetLeaderBoardScoreList(string type, int skip, int limit, TypedCallback<object> callback)

Description


Attempts to fetch the leaderboard score list as the first parameter in the callback function, from the given parameters.

Parameters

Callback Parameters

Example Usage

local my_record
DCEI.GetLeaderBoardScore("type1", function(result)
    my_record = result
end)
-- Results will start at the previous multiple of 10.
local skip = math.floor((my_record.rank - 1) / 10) * 10
-- Obtain the next 10 results.
local limit = 10;

DCEI.GetLeaderBoardScoreList("type1", skip, limit, function(result)
    local text = string.format("Group %s\n", GetGroupName(result.group))
    for _, user in ipairs(result.users) do
        -- Highlight myself.
        if user.uuid == myid then
            text = text .. "<color=red>" .. Format(user) .. "</color>".. "\n"
        else
            text = text .. Format(user) .. "\n"
        end
    end
    DCEI.LogMessage(text)
end)

function Format(record)
    return string.format("Rank %d, Score %f, User %s, %s", record.rank, record.score, record.uuid, record.payload)
end

void GetLeaderBoardSurroundingUsers(string type, int count, TypedCallback<object> callback)

void GetLeaderBoardSurroundingUsers(string type, int count, TypedCallback<object> callback)

Description


Attempts to fetch the leaderboard scores for the current player and the users surrounding them, as the first parameter of the callback function.

Parameters

Callback Parameters

Example Usage

local my_record
DCEI.GetLeaderBoardScore("type1", function(result)
    my_record = result
end)
-- Results will start at the previous multiple of 10.
local skip = math.floor((my_record.rank - 1) / 10) * 10
-- Obtain the next 10 results.
local limit = 10;

DCEI.GetLeaderBoardSurroundingUsers("type1", 3, function(result)
    local text = string.format("Group %s\n", GetGroupName(result.group))
    for _, user in ipairs(result.users) do
        -- Highlight myself.
        if user.uuid == myid then
            text = text .. "<color=red>" .. Format(user) .. "</color>".. "\n"
        else
            text = text .. Format(user) .. "\n"
        end
    end
    DCEI.LogMessage(text)
end)

function Format(record)
    return string.format("Rank %d, Score %f, User %s, %s", record.rank, record.score, record.uuid, record.payload)
end

void GetLeaderBoardUserScores(string type, List<string> uuids, TypedCallback<object> callback)

void GetLeaderBoardUserScores(string type, List<string> uuids, TypedCallback<object> callback)

Description


Returns leader board info for a list of users. Leader board entries returned by leader board APIs now have two additional fields: tag and name.

Parameters

Callback Parameters

Example Usage

local function ResultCallback(result)
    if result then
        -- update player's data, only when player has network
        local self_data = player.race_event.players[1]
        self_data.cur_score = wave.data.GetMax()
        -- fake some data
        -- self_data.cur_score = self_data.cur_score + math.random(30, 40)
        for n, user in ipairs(result.users) do
            for i = 2, player_count do
                local other_player = player.race_event.players[i]
                if other_player.uuid == user.uuid then
                    other_player.cur_score = math.floor(user.score)
                    -- fake some data
                    -- other_player.cur_score = other_player.cur_score + math.random(20, 30)
                    break
                end
            end
        end
        local temp_list = {}
        local start_rank = 0
        local finish_num = 0
        local total_progress = 0
        for i = 1, player_count do
            local player_data = player.race_event.players[i]
            if player_data.finish then
                start_rank = start_rank + 1
                finish_num = finish_num + 1
            else
                local progress_increment = player_data.cur_score - player_data.prev_score
                local cur_progress = player_data.progress + progress_increment
                if player.race_event.team_event then
                    total_progress = total_progress + cur_progress
                else
                    if cur_progress >= RACE_EVENT_TOTAL_PROGRESS then
                        cur_progress = RACE_EVENT_TOTAL_PROGRESS
                        player_data.finish = true
                        finish_num = finish_num + 1
                    end
                end
                local temp_data = {
                    id = i,
                    progress = cur_progress
                }
                table.insert(temp_list, temp_data)
            end
        end
        if #temp_list > 0 then
            local function sort_by_progress(a, b)
                if a.progress == b.progress then
                    return a.id < b.id
                else
                    return a.progress > b.progress
                end
            end
            table.sort(temp_list, sort_by_progress)
            for i = 1, #temp_list do
                local id = temp_list[i].id
                player.race_event.players[id].rank = start_rank + i
            end
        end
        if player.race_event.team_event then
            player.race_event.total_progress = total_progress
            if total_progress >= TEAM_EVENT_TOTAL_PROGRESS then
                player.race_event.event_set = true
                if self_data.rank <= 3 then
                    player.race_event.rank_reward = self_data.rank
                end
            end
        else
            if self_data.finish and self_data.rank <= 3 then
                player.race_event.rank_reward = self_data.rank
                player.race_event.event_set = true
            end
            if finish_num >= 3 then
                player.race_event.event_set = true
            end
        end
        Bank:CommitRaceEvent()
    end
    ui.race_event_banner.fetching = false
end
DCEI.LogMessage("Fetching Race event data")
DCEI.GetLeaderBoardUserScores("default", uuid_list, ResultCallback)

void InitializeInAppPurchaseWithProductId(TypedCallback<string> purchaseCallback, List<string> productIds, TypedCallback<bool> initializationCallback = default)

void InitializeInAppPurchaseWithProductId(TypedCallback<string> purchaseCallback, List<string> productIds, TypedCallback<bool> initializationCallback = default)

Description


Initializes an in-app purchase. This will pass the product IDs to both callback functions.

Parameters

Callback Parameters

Example Usage

function PurchaseCallback(product_id)
    -- Handle successful purchase
end

function InitCallback(success)
    -- Handle initialization completion
end

local product_ids = {"prod_1", "prod_2"}
DCEI.InitializeInAppPurchaseWithProductId(PurchaseCallback, product_ids, InitCallback)

void InitializeInAppPurchaseWithProductData(TypedCallback<string> purchaseCallback, CustomIapProductData customIapProductData, TypedCallback<bool> initializationCallback = default)

void InitializeInAppPurchaseWithProductData(TypedCallback<string> purchaseCallback, CustomIapProductData customIapProductData, TypedCallback<bool> initializationCallback = default)

Description


Initializes an in-app purchase. This will pass the product's ID to both callback functions.

Parameters

Callback Parameters

Example Usage

function PurchaseCallback(product_id)
    -- Handle successful purchase
end

function InitCallback(success)
    -- Handle initialization completion
end

local product_list = DCEI.CreateCustomIapProductData()
DCEI.InitializeInAppPurchaseWithProductData(PurchaseCallback, product_list, InitCallback)

void PurchaseIapProduct(string productId)

void PurchaseIapProduct(string productId)

Description


Begin the purchase of an in-app product. If successful, it will call the InitializeInAppPurchase from DCEI.InitializeInAppPurchase() with the product id as the first parameter. Typically used in conjunction with the IAP Shop Mod.

Parameters

Example Usage

local function AttemptAnyItemPurchase(product_id, on_success)
    -- Typically, we first determine if the store purchase is real money or in-game currency
    if in_game_money then
        -- This would contain separate logic for handing purchases with in-game currency (gold, gems)
        -- As this doesn't need to communicate with vendor (iOS store, google play store)
    else
        -- mark purchase type as IAP
        -- purchase isn't logged here as it can fail during the DCEI.PurchaseIapProduct process
        IS_PURCHASE_IAP = true

        -- standard IAP flow
        if Util.IsPlayingEditorMode() then
            -- simulate purchase in editor
            Shop.OnAnyItemPurchase(product_id)
        else
            DCEI.PurchaseIapProduct(product_id)
        end
    end

    -- DEBUG
    DCEI.LogWarning("> on attempt purchase [ " .. tostring(product_id) .. "]")
end

-- INITIALIZE
local function InitializeShop()
    -- Initializing the shop, we us the above `AttemptAnyItemPurchase` as the `on_purchase_attempt_callback` parameter
    Shop.InitializeIAP({
        on_purchase_attempt_callback = AttemptAnyItemPurchase,
        on_purchase_success_callback = OnAnyItemPurchase,
        product_list = product_list,
        currency_list = currency_list,
        rows_to_load_instantly = 3,
    })
end

string GetIapProductLocalizedPrice(string productId)

string GetIapProductLocalizedPrice(string productId)

Description


Returns the in-app product's localized price, given its ID.

Parameters

Example Usage

local localized_price = DCEI.GetIapProductLocalizedPrice(product_id)
DCEI.LogMessage(localized_price)

void PostLeaderBoardScore(string type, double score, string payload, int spentGems, TypedCallback<object> callback)

void PostLeaderBoardScore(string type, double score, string payload, int spentGems, TypedCallback<object> callback)

Description


Attempts to post the player's score to the given leaderboard.

Parameters

Callback Parameters

Example Usage

local my_score = math.random(1, 100)
local my_record

DCEI.PostLeaderBoardScore("type1", my_score, "I'm here", 0, function(result)
    my_record = result
end)

void SetUserName(string name, TypedCallback<int> callback)

void SetUserName(string name, TypedCallback<int> callback)

Description


Attempts to set a player's username.

Parameters

Callback Parameters

Example Usage

function OnMapStart()
    DCEI.SetUserName("Username", function(result)
        local user_name = DCEI.GetUserName()
        DCEI.LogMessage(user_name)
        DCEI.LogMessage(result)
    end)
end