Trigger API Reference DCEI Functions Service0 - funovus/editor-wiki GitHub Wiki

Table of Contents
- [Trigger API Reference\DCEI Functions\Service (1/2)](#trigger-api-referencedcei-functionsservice-12) * [string GetTranslationText(string key, Dictionary parameters)](#string-gettranslationtextstring-key-dictionarystring-object-parameters) * [bool IsAdsReady()](#bool-isadsready) * [void ShowAds(TypedCallback callback, bool fallbackToUnityAds)](#void-showadstypedcallbackbool-callback-bool-fallbacktounityads) * [bool IsOnline()](#bool-isonline) * [bool IsDev()](#bool-isdev) * [void ShowSettings()](#void-showsettings) * [void GetSaveDataHistory(int count, TypedCallback callback)](#void-getsavedatahistoryint-count-typedcallbackobject-callback) * [void ResetSavedMapDataByIndex(int index)](#void-resetsavedmapdatabyindexint-index) * [void GetMail(TypedCallback callback, bool forceFetch)](#void-getmailtypedcallbackobject-callback-bool-forcefetch) * [void DeleteMail(int instanceId)](#void-deletemailint-instanceid) * [int ScheduleNotification(string title, string body, double timeInSeconds)](#int-schedulenotificationstring-title-string-body-double-timeinseconds) * [void CancelNotification(int id)](#void-cancelnotificationint-id) * [object GetLastNotificationId()](#object-getlastnotificationid) * [void ShowSendSMS(int platform)](#void-showsendsmsint-platform) * [void RestartApplication()](#void-restartapplication) * [void OpenUrl(string url)](#void-openurlstring-url) * [void RequestAppStoreReview()](#void-requestappstorereview) * [void RequestInAppReview(Action successCallback, Action failureCallback)](#void-requestinappreviewaction-successcallback-action-failurecallback) * [void GetServerTime(TypedCallback callback)](#void-getservertimetypedcallbackint-callback) * [string GetUserId()](#string-getuserid) * [string GetUserName()](#string-getusername) * [string GetUserTag()](#string-getusertag) * [void GetLeaderBoardScore(string type, TypedCallback callback)](#void-getleaderboardscorestring-type-typedcallbackobject-callback) * [void GetLeaderBoardScoreList(string type, int skip, int limit, TypedCallback callback)](#void-getleaderboardscoreliststring-type-int-skip-int-limit-typedcallbackobject-callback) * [void GetLeaderBoardSurroundingUsers(string type, int count, TypedCallback callback)](#void-getleaderboardsurroundingusersstring-type-int-count-typedcallbackobject-callback) * [void GetLeaderBoardUserScores(string type, List uuids, TypedCallback callback)](#void-getleaderboarduserscoresstring-type-liststring-uuids-typedcallbackobject-callback) * [void InitializeInAppPurchaseWithProductId(TypedCallback purchaseCallback, List productIds, TypedCallback initializationCallback)](#void-initializeinapppurchasewithproductidtypedcallbackstring-purchasecallback-liststring-productids-typedcallbackbool-initializationcallback) * [void InitializeInAppPurchaseWithProductData(TypedCallback purchaseCallback, CustomIapProductData customIapProductData, TypedCallback initializationCallback)](#void-initializeinapppurchasewithproductdatatypedcallbackstring-purchasecallback-customiapproductdata-customiapproductdata-typedcallbackbool-initializationcallback) * [void PurchaseIapProduct(string productId)](#void-purchaseiapproductstring-productid) * [string GetIapProductLocalizedPrice(string productId)](#string-getiapproductlocalizedpricestring-productid)

Trigger API Reference\DCEI Functions\Service (1/2) {Trigger-API-ReferenceDCEI-FunctionsService-12}

string GetTranslationText(string key, Dictionary<string, object> parameters) {string-GetTranslationTextstring-key-Dictionarystring-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

  • string key the localization key to use.
  • Dictionary parameters (optional) a table of replacement text keys.

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)

bool IsAdsReady() {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) {void-ShowAdsTypedCallbackbool-callback-bool-fallbackToUnityAds}

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

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

  • object callback this callback function is called once ShowAds() has resolved. If watching ads was successful, the first parameter of this callback function will return true.
  • bool fallbackToUnityAds if true, uses unity ads as a fallback.

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}

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}

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

void ShowSettings() {void-ShowSettings}

void ShowSettings()

Description

Show the game settings menu. Only works on mobile.

Example Usage

DCEI.ShowSettings()

void GetSaveDataHistory(int count, TypedCallback<object> callback) {void-GetSaveDataHistoryint-count-TypedCallbackobject-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

  • int count the number of save data instances to include in the callback table, with the most recent saves returned first. Max 10.
  • object callback the callback function to handle the returned save data instances.

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.GetSaveDataHistory(count, ResultCallback)

void ResetSavedMapDataByIndex(int index) {void-ResetSavedMapDataByIndexint-index}

void ResetSavedMapDataByIndex(int index)

Description

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

Parameters

  • int index the saved map data index to reset.

Example Usage

DCEI.ResetSavedMapDataByIndex(1)

void GetMail(TypedCallback<object> callback, bool forceFetch) {void-GetMailTypedCallbackobject-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

  • object callback the callback function to handle the returned mail.
  • bool forceFetch if true, forces a fetch.

Example Usage

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

void DeleteMail(int instanceId) {void-DeleteMailint-instanceId}

void DeleteMail(int instanceId)

Description

Attempts to delete the mail with the given ID.

Parameters

  • int instanceId the ID of the mail to delete.

Example Usage

DCEI.DeleteMail(1)

int ScheduleNotification(string title, string body, double timeInSeconds) {int-ScheduleNotificationstring-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

  • string title the title of the notification.
  • string body the body text of the notification.
  • double timeInSeconds the duration to wait before triggering the notification.

Example Usage

DCEI.ScheduleNotification("Title", "Notification", 120)

void CancelNotification(int id) {void-CancelNotificationint-id}

void CancelNotification(int id)

Description

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

Parameters

  • int id the ID of the notification to cancel.

Example Usage

DCEI.CancelNotification(1)

object GetLastNotificationId() {object-GetLastNotificationId}

object GetLastNotificationId()

Description

Returns the last notification ID. Only works on mobile.

Example Usage

local last_notif_id = DCEI.GetLastNotificationId()

void ShowSendSMS(int platform) {void-ShowSendSMSint-platform}

void ShowSendSMS(int platform)

Description

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

Parameters

  • int platform the platform used to send the SMS. Use 1 for Android and 2 for iOS.

Example Usage

DCEI.ShowSendSMS(1)

void RestartApplication() {void-RestartApplication}

void RestartApplication()

Description

Restarts the application. Only works on mobile.

Example Usage

DCEI.RestartApplication()

void OpenUrl(string url) {void-OpenUrlstring-url}

void OpenUrl(string url)

Description

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

Parameters

  • string url the url to open.

Example Usage

DCEI.OpenUrl("https://github.com/funovus/editor-wiki/wiki/Trigger-API-Reference-DCEI-Functions-Service0#openurl")

void RequestAppStoreReview() {void-RequestAppStoreReview}

void RequestAppStoreReview()

Description

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

Example Usage

DCEI.RequestAppStoreReview()

void RequestInAppReview(Action successCallback, Action failureCallback) {void-RequestInAppReviewAction-successCallback-Action-failureCallback}

void RequestInAppReview(Action successCallback, Action failureCallback)

Description

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

Parameters

  • Action successCallback the action that is taken on a successful review.
  • Action failureCallback the action that is taken on a failed review.

Example Usage

DCEI.RequestInAppReview(SuccessCallback, FailureCallback)

void GetServerTime(TypedCallback<int> callback) {void-GetServerTimeTypedCallbackint-callback}

void GetServerTime(TypedCallback<int> callback)

Description

Attempts to return the server time as the first parameter of a callback function.

Parameters

  • object callback the callback function that handles the server time.

Example Usage

local function ResultCallback( time_stamp )
  if time_stamp 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.

string GetUserId() {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}

string GetUserName()

Description

Returns the player's username.

Example Usage

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

string GetUserTag() {string-GetUserTag}

string GetUserTag()

Description

Returns the player's tag.

Example Usage

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

void GetLeaderBoardScore(string type, TypedCallback<object> callback) {void-GetLeaderBoardScorestring-type-TypedCallbackobject-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

  • string type the leaderboard score to fetch.
  • object callback the callback function to handle the score.

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-GetLeaderBoardScoreListstring-type-int-skip-int-limit-TypedCallbackobject-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

  • string type the leaderboard score to fetch.
  • int skip the number of entries to skip.
  • int limit the number of entries to return after the skip.
  • object callback the callback function to handle the score list.

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-GetLeaderBoardSurroundingUsersstring-type-int-count-TypedCallbackobject-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

  • string type the leaderboard to fetch from.
  • int count the number of users to return, including the player themselves.
  • object callback the callback function to handle the score list.

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-GetLeaderBoardUserScoresstring-type-Liststring-uuids-TypedCallbackobject-callback}

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

Description

  • string type the leaderboard to fetch from.
  • List uuids players' uuids
  • object callback the callback function to handle the score list.

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) {void-InitializeInAppPurchaseWithProductIdTypedCallbackstring-purchaseCallback-Liststring-productIds-TypedCallbackbool-initializationCallback}

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

Description

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

Parameters

  • object purchaseCallback the callback function on a successful purchase.
  • table productIds a table containing the in-app product IDs.
  • object initializationCallback the callback function for

Example Usage

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

void InitializeInAppPurchaseWithProductData(TypedCallback<string> purchaseCallback, CustomIapProductData customIapProductData, TypedCallback<bool> initializationCallback) {void-InitializeInAppPurchaseWithProductDataTypedCallbackstring-purchaseCallback-CustomIapProductData-customIapProductData-TypedCallbackbool-initializationCallback}

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

Description

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

Parameters

  • object purchaseCallback the callback function on a successful purchase.
  • CustomIapProductData customIapProductData the custom in-app product data to be purchased.
  • object initializationCallback the callback function for initialization.

Example Usage

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

void PurchaseIapProduct(string productId) {void-PurchaseIapProductstring-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.

Parameters

  • string productId the ID of the product to be purchased.

Example Usage

DCEI.PurchaseIapProduct(product_id)

string GetIapProductLocalizedPrice(string productId) {string-GetIapProductLocalizedPricestring-productId}

string GetIapProductLocalizedPrice(string productId)

Description

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

Parameters

  • string productId the ID of the product to return the localized price of.

Example Usage

local localized_price = DCEI.GetIapProductLocalizedPrice(product_id)

⚠️ **GitHub.com Fallback** ⚠️