question

jonbrooks977 avatar image
jonbrooks977 asked

Updating Character Data

I'm not quite sure how the "Characters" system works here in PlayFab but I was hoping to be able to store character stats with it. The following code is what I am currently trying to do, but I am having issues with Data | Object<Key, Value>

The ErrorMessage returned through OnPlayFabError is "Invalid input parameters" but I don't know what is invalid here. Any idea as to what I should be trying to fix?

Dictionary<string, string> ZeroesDictionary = new Dictionary<string, string>();


		ZeroesDictionary.Add("Level", "1");
		ZeroesDictionary.Add("Mining", "1");
		ZeroesDictionary.Add("Picking", "1");
		ZeroesDictionary.Add("Cooking", "1");
		ZeroesDictionary.Add("Metal", "1");


  		UpdateCharacterDataRequest uprequest = new UpdateCharacterDataRequest()
		{
			CharacterId = currentCharID,
  			Data = ZeroesDictionary,
  			Permission = UserDataPermission.Public
		};


		PlayFabClientAPI.UpdateCharacterData(uprequest, OnZeroesResult, OnPlayFabError);

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

If you check the full error return, there's an errorDetails that contains additional context on any error you run into. In this case though, the issue is that statistics are not strings - they are int32 values. Also, while it won't throw an error (because it'll be ignored), Permission isn't part of a statistics call, as they are always available publicly (all statistics are leaderboards). If you don't need players to be able to compare these values in a leaderboard, you may want to consider using Character Data instead. Personally, I'd advise using Character Read Only Data, so that you can control updates in Cloud Script to prevent cheating. Also, you should store all the stats in a single Key/Value pair in that case, since small data values aren't efficient.

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.

jonbrooks977 avatar image jonbrooks977 commented ·

I am using Character Data. Not Read-Only, but I am using Character Data. That's why I am having this issue with UpdateCharacterDataRequest. I need to be able to make changes when a player kills a monster or collects a material. How can I do this using Cloud Script to automatically change when these events happen in game?

0 Likes 0 ·
brendan avatar image brendan jonbrooks977 commented ·

Whoop - sorry, I saw your statement that you were storing "stats" in the original question, and got confused, obviously.

What do the errorDetails show in the error returned from your call?

I do need to also ask though, how often could a player kill a monster or collect a material? I ask because those sound like high-frequency activities for most games. If that's the case, you should not be trying to update the back end every time, as the call rate would exceed our fair use policy. Rather, you should only update when key events occur, like major achievements or level completion, or when a certain amount of time has passed otherwise (a couple of minutes, usually).

If you'd rather use Character Read Only Data via Cloud Script, you could use a design pattern similar to that shows to write to User Read Only Data in our ReferralCode sample:

https://github.com/PlayFab/PlayFab-Samples/blob/bdd8b779036eeae26e0ee3d4ef0407093783f6b9/Recipes/ReferralCodes/CloudScript.js

With the obvious difference being that you would add the CharacterId to the call.

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.