question

yzx2002 avatar image
yzx2002 asked

how to grant a character to user and update it's statistic in cloud script?

I can grant a character to player in cloud script , but at the same time I want to update the statistic. how can I got the characterId I created just now? I use grantAssistantPet.CharacterId, but it fail.

var grantAssistantPet = server.GrantCharacterToUser ({
        PlayFabId : currentPlayerId,
        CharacterName : "Monkey",
        CharacterType : "Fire"
    });


    var updatePetStatistics = server.UpdateCharacterStatistics ({
        PlayFabId : currentPlayerId,
        CharacterId : grantAssistantPet.CharacterId,
        CharacterStatistics : [
            {
            "StatisticName": "Level",
            "Value": 1 
            },
            {
            "StatisticName": "Experience",
            "Value": 0 
            }
        ]


    });
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

·
brendan avatar image
brendan answered

Yes, the response to the call to grant a character does contain the character ID. Are you saying you're encountering an issue with the code above? What is the specific error being returned from the call to UpdateCharacterStatistics? Have you tried making the call in Postman to check the response? What is the Title ID for the test?

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

yzx2002 avatar image yzx2002 commented ·

I tested in postman by input character id manually, it works well.

CharacterId: grantAssistantPet.CharacterId

I wonder this code above can't get the characterid.

Title 7FB0

0 Likes 0 ·
brendan avatar image brendan yzx2002 commented ·

Oh - I just noticed that you have the stats in there the way you would for a call to UpdatePlayerStatistics. That's actually incorrect. The UpdateCharacterStatistics call in your script should look like this:

    var updatePetStatistics = server.UpdateCharacterStatistics ({
        PlayFabId : currentPlayerId,
        CharacterId : grantAssistantPet.CharacterId,
        CharacterStatistics : {
            "Level": 1,
            "Experience": 0 
        }
    });
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.