question

forplayers.co avatar image
forplayers.co asked

[Server API] Can't retrive "PlayfabId" from GetLeaderboardResult for google accounts

Hi,

Few months ago, I created a cloud script that adds virtual currency for the best players of the day. I was working flawlessly but since I added the possibility to login with a google account, I always get this error:

{
    "TaskInstanceId": "xxxxxxxxxxx",
    "TaskIdentifier": {
        "Name": "Reward [Arena]",
        "Id": "xxxxxxxxxxx"
    },
    "StartedAt": "2017-09-15T00:00:07.1367384",
    "CompletedAt": "2017-09-15T00:00:08.8337511",
    "Status": "Failed",
    "PercentComplete": null,
    "EstimatedSecondsRemaining": null,
    "ScheduledByUserId": null,
    "Result": {
        "FunctionName": "RewardArena",
        "Revision": 21,
        "FunctionResult": null,
        "FunctionResultTooLarge": null,
        "Logs": [],
        "LogsTooLarge": null,
        "ExecutionTimeSeconds": 0.4272996,
        "ProcessorTimeSeconds": 0,
        "MemoryConsumedBytes": 4294722104,
        "APIRequestsIssued": 6,
        "HttpRequestsIssued": 0,
        "Error": {
            "Error": "JavascriptException",
            "Message": "JavascriptException",
            "StackTrace": "TypeError: Cannot read property 'PlayFabId' of undefined\n    at handlers.RewardArena (E53F-main.js:36:59)"
        }
    }
}

Here is the concerned part of the code:

var getStatisticVersionsResult = server.GetPlayerStatisticVersions({
        StatisticName: "BestDailyPlayer"
    });
 var getStatisticVersionsResult = server.GetPlayerStatisticVersions({
        StatisticName: "BestDailyPlayer"
    });
    var version = getStatisticVersionsResult.StatisticVersions[0].Version;
    var useSpecific = false;
    if (version != 0) {
        useSpecific = true;
    }
    var getLeaderboardResult = server.GetLeaderboard({
        StatisticName : "BestDailyPlayer",
        StartPosition : 0,
        MaxResultsCount : 3,
        UseSpecificVersion : useSpecific,
        Version: version
    });
    SetVirtualCurrency(getLeaderboardResult.Leaderboard[0].PlayFabId, "02", 50);
    SetVirtualCurrency(getLeaderboardResult.Leaderboard[0].PlayFabId, "03", 1);
    SetVirtualCurrency(getLeaderboardResult.Leaderboard[1].PlayFabId, "02", 40);
    SetVirtualCurrency(getLeaderboardResult.Leaderboard[2].PlayFabId, "02", 35);
    SetVirtualCurrency(getLeaderboardResult.Leaderboard[3].PlayFabId, "02", 30);
    SetVirtualCurrency(getLeaderboardResult.Leaderboard[4].PlayFabId, "02", 25);
    SetVirtualCurrency(getLeaderboardResult.Leaderboard[5].PlayFabId, "02", 20);
    SetVirtualCurrency(getLeaderboardResult.Leaderboard[6].PlayFabId, "02", 18);
    SetVirtualCurrency(getLeaderboardResult.Leaderboard[7].PlayFabId, "02", 16);
    SetVirtualCurrency(getLeaderboardResult.Leaderboard[8].PlayFabId, "02", 14);
    SetVirtualCurrency(getLeaderboardResult.Leaderboard[9].PlayFabId, "02", 12);

P.S. The leaderboard length is always superior than 10 so it's not an index problem.

Thanks

1 comment
10 |1200

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

forplayers.co avatar image forplayers.co commented ·

Sorry for the mistakes, I can't modity my post. I wanted to say: "It was working flawlessly"

0 Likes 0 ·

1 Answer

·
brendan avatar image
brendan answered

The PlayFab ID is always returned with leaderboard results, regardless. However, I do notice that you're asking for a max of 3 results in your call to GetLeaderboard, while the SetVirtualCurrency calls are attempting to act on 10 leaderboard entries. Could you check that you're polling for at least 10 results in the live version of your script?

6 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.

forplayers.co avatar image forplayers.co commented ·

Thank you for the reply,

No, I didn't set the "MaxResultsCount ". In the new docs I saw that it was now requiered. I don't remember it was requiered few months ago... It seems to me that there was a default value.

Anyways I set the MaxResultsCount to 10 and uploaded a new revision. I'll keep you updated of the results

0 Likes 0 ·
brendan avatar image brendan forplayers.co commented ·

I understand the confusion - the MaxResultsCount is not required for the Client API call, but is required for the Server API call. That's not a change, it's just an inconsistency (I'll file a bug to change the Server one to not be required to help with that). We don't ever change an existing API parameter from not required to required, as that would be a breaking change for existing titles.

0 Likes 0 ·
forplayers.co avatar image forplayers.co commented ·

It still gives me this error but I noticed that I also forgot to set the StartPosition field. However there is something mysterious. If nothing changed in the Server API, then how to explain that there wasn't any problem before? You can see on the picture when did it started to fail.

0 Likes 0 ·
capture-decran-5.png (106.7 KiB)
forplayers.co avatar image forplayers.co commented ·

Ok, I feel a bit embarrassed. I checked the revision version of Reward [Anena]-98 and 99 to show you that it was on the same version but I realized that it wasn't the case. In the previous I had done everything the right way :

var getLeaderboardResult = server.GetLeaderboard({
        StatisticName : "BestDailyPlayer",
        StartPosition : 0,
        MaxResultsCount : 3,
        UseSpecificVersion : useSpecific,
        Version: version
    });
    SetVirtualCurrency(getLeaderboardResult.Leaderboard[0].PlayFabId, "02", 42);
    SetVirtualCurrency(getLeaderboardResult.Leaderboard[0].PlayFabId, "03", 1);
    SetVirtualCurrency(getLeaderboardResult.Leaderboard[1].PlayFabId, "02", 21);
    SetVirtualCurrency(getLeaderboardResult.Leaderboard[2].PlayFabId, "02", 12);

I didn't even remebered that I had changed it.

Sorry for the wasted time but as I saw, this will have contributed to ameliorate a bit the server API.

Thank you for the fast and helpful support

0 Likes 0 ·
forplayers.co avatar image forplayers.co commented ·

Brendan, I think that you told yourself many times that what I was saying made no sense (e.g."I also forgot to set the StartPosition field" whereas you were clearly seeing in my code that it was already defined). Just for forget it, my cloudscript was a real jungle and I was modifying other functions.

0 Likes 0 ·
brendan avatar image brendan forplayers.co commented ·

No worries - I'm just glad you got the info you need. Let us know if you have any other questions.

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.