question

Kim Strasser avatar image
Kim Strasser asked

Title exceeded limit when I want to grant leaderboard rewards

I need to find a way to grant rewards after a weekly tournament. The reset frequency for the leaderboard is set to manually. I have tried to grant the rewards with scheduled tasks after the weekly tournament finished. My scheduled task calls the CloudScript function GrantingLeaderboardRewardsToPlayer. In this function, I sort the current leaderboard. I need to sort the leaderboard in CloudScript because I use two different statistics to sort the current leaderboard.

But I always get the error message "Title exceeded limit":

"EventName": "title_exceeded_limit",
    "LimitId": "CloudScript:ScriptExecutionAPIRequestsIssued",
    "LimitDisplayName": "Number of PlayFab API requests made from a CloudScript function called by the ExecuteCloudScript API.",
    "Unit": "Count",
    "LimitValue": 25,
    "Value": 26,

In my CloudScript function, I grant the rewards to the best 100 players in the leaderboard. But I cannot grant the rewards to the 100 players because I get the error message "Title exceeded limit".

handlers.GrantingLeaderboardRewardsToPlayer = function (args, context)
{
    // sort the leaderboard

    // Grant the rewards to the best 100 players:
    var rewardsrange;
    for (var j = 0; j <= sortedplayerslist.length - 1; j++)
    {
    var playerrank = Number(j) + 1;
    if (Number(playerrank) == 1)
        rewardsrange = 1;
    if (Number(playerrank) == 2)
        rewardsrange = 2;
    if (Number(playerrank) == 3)
        rewardsrange = 3;
    if ((Number(playerrank) > 3) && (Number(playerrank) <= 10))
        rewardsrange = 4;
    if ((Number(playerrank) > 10) && (Number(playerrank) <= 20))
        rewardsrange = 5;
    if ((Number(playerrank) > 20) && (Number(playerrank) <= 50))
        rewardsrange = 6;
    if ((Number(playerrank) > 50) && (Number(playerrank) <= 100))
        rewardsrange = 7;       
 
    switch (Number(rewardsrange))
    {
        case 1:
        var updatecurrencysucc = false;
        var updatecurrency = server.AddUserVirtualCurrency({PlayFabID: sortedplayerslist[j].Playfabid, VirtualCurrency: "GO", Amount: 1000});
        if ((updatecurrency != null) && (updatecurrency.Error == null))
            updatecurrencysucc = true;
        else
            updatecurrencysucc = false;
        break;
        case 2:
        var updatecurrencysucc = false;
        var updatecurrency = server.AddUserVirtualCurrency({PlayFabID: sortedplayerslist[j].Playfabid, VirtualCurrency: "GO", Amount: 800});
        if ((updatecurrency != null) && (updatecurrency.Error == null))
            updatecurrencysucc = true;
        else
            updatecurrencysucc = false;
        break;
        case 3:
        var updatecurrencysucc = false;
        var updatecurrency = server.AddUserVirtualCurrency({PlayFabID: sortedplayerslist[j].Playfabid, VirtualCurrency: "GO", Amount: 500});
        if ((updatecurrency != null) && (updatecurrency.Error == null))
            updatecurrencysucc = true;
        else
            updatecurrencysucc = false;
        break;
        case 4:
        var updatecurrencysucc = false;
        var updatecurrency = server.AddUserVirtualCurrency({PlayFabID: sortedplayerslist[j].Playfabid, VirtualCurrency: "GO", Amount: 350});
        if ((updatecurrency != null) && (updatecurrency.Error == null))
            updatecurrencysucc = true;
        else
            updatecurrencysucc = false;
        break;
        case 5:
        var updatecurrencysucc = false;
        var updatecurrency = server.AddUserVirtualCurrency({PlayFabID: sortedplayerslist[j].Playfabid, VirtualCurrency: "GO", Amount: 200});
        if ((updatecurrency != null) && (updatecurrency.Error == null))
            updatecurrencysucc = true;
        else
            updatecurrencysucc = false;
        break;
        case 6:
        var updatecurrencysucc = false;
        var updatecurrency = server.AddUserVirtualCurrency({PlayFabID: sortedplayerslist[j].Playfabid, VirtualCurrency: "GO", Amount: 100});
        if ((updatecurrency != null) && (updatecurrency.Error == null))
            updatecurrencysucc = true;
        else
            updatecurrencysucc = false;
        break;
        case 7:
        var updatecurrencysucc = false;
        var updatecurrency = server.AddUserVirtualCurrency({PlayFabID: sortedplayerslist[j].Playfabid, VirtualCurrency: "GO", Amount: 50});
        if ((updatecurrency != null) && (updatecurrency.Error == null))
            updatecurrencysucc = true;
        else
            updatecurrencysucc = false;
        break;
    }
    }

    // notify the player when he got a reward

    return;
}

How can I grant the rewards to the 100 players when I cannot do more than 25 API requests in my CloudScript function?

In addition, I will use at least one more API call for each of the 100 players because I need to notify the players. That would already be 200 API calls only for granting and notifying the players.

CloudScriptLeaderboards and Statisticsscheduled tasks
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Seth Du avatar image
Seth Du answered

As you can see, the API limit in single Cloud Script/Azure Function (CSAF) execution is stated in the error callback and it cannot be increased.

To grant rewards for all players, you may need to make sure the target players are in a same segment, for example, setting specific Statistic value larger than 0 in the filter. Then in Scheduled task, you may set “Run actions on each player in a segment”, then execute CSAF. Please note that the script will only apply to single player, there is no need to add any for loop to iterate players.

3 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Seth Du avatar image Seth Du ♦ commented ·

In addition, though I believe I have provided a most common solution to your question, please note that the current 25 API limit only applies to Cloud Script. The thing I didn't state clearly is that Azure Function only has 10s runtime limit, and there is no number limit within an execution.

It means that 200 API calls might be done in Azure function but will need your own tests. Meanwhile please also understand that putting so many APIs in one execution can have bad robustness that may affect future management.

0 Likes 0 ·
Kim Strasser avatar image Kim Strasser Seth Du ♦ commented ·

I can only have 5 requests in CloudScript when my function is called by an action trigger.

Does Azure Function have the same limit value or can I have more than 5 API requests in an Azure Function when the function is called by an action trigger?

"EventName": "title_exceeded_limit",
    "LimitId": "PlayStream:TriggeredActionCloudScriptExecutionAPIRequestsIssued",
    "LimitDisplayName": "Number of PlayFab API requests made from a CloudScript function called by an action trigger.",
    "Unit": "Count",
    "LimitValue": 5,
    "Value": 6,
0 Likes 0 ·
Seth Du avatar image Seth Du ♦ Kim Strasser commented ·

Azure function won't have API count limit, however, it still has 1s runtime limit if you implement a HTTP trigger function.

This limit won't apply to queue trigger function, and it will have up to 5 min runtime.

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.