question

Pat avatar image
Pat asked

character help

So i have a few questions about characters with Playfab. So I have the player able to purchase a character and create it but my question is where can i save stats like health, mana, attack power, etc. Do I add custom fields in the Attributes and save them there or is there an easier way? What is the purpose of the character then?

Also is there a way to delete items from a player? I see I can revoke them but they are still there in the players inventory.

10 |1200

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

Pat avatar image
Pat answered

PlayfabID = B7294C1DF7CEA146

CharacterID = 5608179994230520000  

Stats = Level, 1

10 |1200

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

brendan avatar image
brendan answered

Everything looks fine with that character, and the call works in my own testing. Can you send us the code snippet of how you're making the call, and provide the details on the values being passed into the parameters in your repro case?

10 |1200

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

Pat avatar image
Pat answered

 

void OnGrantCharacter(GrantCharacterToUserResult result)
    {

        UpdateCharacterStatisticsRequest request = new UpdateCharacterStatisticsRequest()
        {
            CharacterId = result.CharacterId,
            CharacterStatistics = new Dictionary<string, int>()
            {
                {"Level", 1},
            }
        };

        PlayFabClientAPI.UpdateCharacterStatistics(request, UpdateCharacter, OnError);


    }

The UpdateCharacter function is just setting the scene back to the character select screen. This function is being called as the result of what happens when the character is granted to the player.

10 |1200

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

brendan avatar image
brendan answered

Thanks for pursuing this with us, as it uncovered two issues:

First, your Character ID is actually 4DD441FDC88FF925. It looks like there's a bug in the current Game Manager causing it to show incorrect Character ID values. I've opened a bug on this, so it should be fixed soon.

Meanwhile, the issue with the UpdateCharacterStatistics call is that it was not correctly tagged for the SDK auto-generator as requiring authentication. We'll release an updated SDK Monday that corrects this, but here's the code change, if you have an urgent need:

In PlayFabClientAPI.cs, change this:

public static void UpdateCharacterStatistics(UpdateCharacterStatisticsRequest request, ProcessApiCallback<UpdateCharacterStatisticsResult> resultCallback, ErrorCallback errorCallback, object customData = null)
{
  string serializedJson = JsonConvert.SerializeObject(request, Util.JsonFormatting, Util.JsonSettings);
  Action<CallRequestContainer> callback = delegate(CallRequestContainer requestContainer)
  {
    ResultContainer<UpdateCharacterStatisticsResult>.HandleResults(requestContainer, resultCallback, errorCallback, null);
  };
  PlayFabHTTP.Post("/Client/UpdateCharacterStatistics", serializedJson, null, null, callback, request, customData);
}


to this:

public static void UpdateCharacterStatistics(UpdateCharacterStatisticsRequest request, ProcessApiCallback<UpdateCharacterStatisticsResult> resultCallback, ErrorCallback errorCallback, object customData = null)
{
  if (_authKey == null) throw new Exception("Must be logged in to call this method");
    string serializedJson = JsonConvert.SerializeObject(request, Util.JsonFormatting, Util.JsonSettings);
  Action<CallRequestContainer> callback = delegate(CallRequestContainer requestContainer)
  {
    ResultContainer<UpdateCharacterStatisticsResult>.HandleResults(requestContainer, resultCallback, errorCallback, null);
  };
  PlayFabHTTP.Post("/Client/UpdateCharacterStatistics", serializedJson, "X-Authorization", _authKey, callback, request, customData);
}
10 |1200

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

Pat avatar image
Pat answered

Thank you so much this works now. My final question is can I see the stats in the game manager?

10 |1200

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

brendan avatar image
brendan answered

Not in the current version, but we're about to release a major update to the Game Manager, which does include (among other things) Character statistics viewing and editing. 

10 |1200

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

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.