question

Z. avatar image
Z. asked

Updating Character Statistics

Hi,

Have been having trouble trying to store some Character Statistics. So what I understood from the doc is the Character Stats are also leaderboard values, and have went ahead to create a "UnitLevel" leaderboard value that will be used.

What I couldn't achieve is to create/update those Characters Stats.

So here's how my code looks

var updateCharStats = server.UpdateCharacterStatistics
    ({
        PlayFabId : currentPlayerId,
        CharacterId : "inputCharID",
        CharacterStatistics :
        [
            {Statistics:"UnitLevel", Value:1},
        ]
    });

But it does not update the Character Stats.

Then I though it could be just Statistics instead of CharacterStatistics,

var updateCharStats = server.UpdateCharacterStatistics
    ({
        PlayFabId : currentPlayerId,
        CharacterId : "inputCharID",
        Statistics :
        [
            {Statistics:"UnitLevel", Value:1},

        ]
    });

Which didn't work as well.

And in the docs it states the CharacterStatistics field is an object, so I tried this

var updateCharStats = server.UpdateCharacterStatistics
    ({
        PlayFabId : currentPlayerId,
        CharacterId : "inputCharID",
        Statistics :
        [
            {"UnitLevel",1},

        ]
    });

And it also didn't work.

Would be great if the docs had a template for "visualizing" how it should be written.

Also, I could do with some assistance on getting this to work.

Thanks!

Character Data
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

·
Sarah Zhang avatar image
Sarah Zhang answered

You can refer to the following example to modify the code. We would suggest you test the corresponding API methods in the external REST API testing tool, such as Postman before you call them on CloudScript. The SDK of Postman contains a large number of request bodies’ samples, which can be referenced. Please click the link to check the Postman’s SDK and QuickStart.

handlers.testUpdateCharacterStatistic = function (args, context) {
    var updateCharStats = server.UpdateCharacterStatistics
        ({
            PlayFabId: currentPlayerId,
            CharacterId: "[YourCharacterId]",
            CharacterStatistics:{ "UnitLevel": 1 },
                
        });
};
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.

Z. avatar image Z. commented ·

Thanks for the response!

I was indeed looking for something like this where I could run Cloud Scripts on.

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.