question

Kim Strasser avatar image
Kim Strasser asked

How can I create and update achievements that are visible for all other players?

I want to create achievements in my title account but I don't know how to create them. I always want to update the player's achievements after he finished a level in my game.

Possible achievements that I want to add to my title account:

-Finish this level 5 times-->reward: Granted 100 virtual currency

-Submit your high score of this level to the PlayFab leaderboards-->reward: Granted 100 virtual currency

-Get 500 points in this level-->reward: Granted 200 virtual currency

-Don't get hit in this level-->reward: Granted 300 virtual currency

-Kill all enemies in this level-->reward: Granted a durable item(for example a special sword from the catalog) that you normally need to purchase with virtual currency in the PlayFab shop.

-Win a weekly leaderboard-->reward: Granted a durable item(for example a special sword from the catalog) that you normally need to purchase with virtual currency in the PlayFab shop.

In addition, I want that the all player's achievements are visible to all other players. You don't need to have another player in your friendslist to see his achievements.

How can I create these achievements in my title account? Is it possible to do it in the game manager with READ ONLY DATA in Player Data (Title) or is there a better way to create the achievements?

I want to update/check in CloudScript if a player fulfills the achievements requirements. In addition, I want to count in CloudScript how often a player finished a certain level.

UPDATE:

My CloudScript:

handlers.CreateAchievementsReadOnlyData = function (args, context)
{
   var resultdata = server.GetUserReadOnlyData({PlayFabId: currentPlayerId, Keys: "Finish level 1"}); // first search for the current achievement info
   
   if(resultdata.Data.hasOwnProperty("Finish level 1"))
   { // if achievements info already exists in readonly data
       log.info("Already has achievements info."); // notify the client that Achievements info already been set
   }
   else
   {// if achievements info hasn't been set yet, set it for the user
       server.UpdateUserReadOnlyData({
           PlayFabId: currentPlayerId,
           Data: {
               //The first 5 achievements belong to one certain level in the game, for example level 1.
               "Finish level 1": "false",
               "Finish this level 3 times": "0",
               "Submit your high score of this level to the PlayFab leaderboards": "false",
               "Get 400 points in this level": "false",
               "Don't get hit in this level": "false",
               "Kill all enemies in this level": "false",
               //The next 5 achievements belong to one certain level in the game, for example level 2.
               "Finish level 2": "false",
               "Finish this level 5 times": "0",
               "Submit your high score of this level to the PlayFab leaderboards": "false",
               "Get 600 points in this level": "false",
               "Don't get hit in this level": "false",
               "Collect 5 treasures in this level": "0",
               //The next achievements are special achievements, they don't belong to a certain level in the game.
               "Win a weekly leaderboard": "0",
               "Finish 100 levels": "0",
               "Get 10.000 points": "0", // You get points after you finiseh a level. I want to sum all points and check if the player has reached 10.000 points.
           }
        });
        
      log.info("Achievements info has now been set."); 
   }
   
   return resultdata;
}

Client code:

private async Task CreatePlayerAchievements()
{
    var result = await PlayFabClientAPI.ExecuteCloudScriptAsync(new ExecuteCloudScriptRequest()
    {
        FunctionName = "CreateAchievementsReadOnlyData",
        GeneratePlayStreamEvent = true
    });

    if (result.Error != null)
        Console.WriteLine(result.Error.Error.ToString());
    else
    {
        if (result.Result.Logs.Count() > 0)
            Console.WriteLine(result.Result.Logs[0].Message);             
    }
}
Player DataCloudScript
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

·
Seth Du avatar image
Seth Du answered

The contents of Achievement can be stored in Title Data, since it is a shared resource and won’t be changed frequently. When Player start the game, The client will retrieve the title data and store locally in the client. Player Read-Only data is a good place to store the marks of achievement progress and when a challenge is completed, the player will click a “receive rewards” button, which will execute a cloud script function to firstly, check if the player is qualified, then gran the rewards.

Player Read-only Data can be public or private. If it is set public, when other players get profiles from him, the public player read-only data can be exposed to them. You may see the permission option at the end of a player data entry. Be aware that all the progress data should be stored in player read-only data or player internal data, where player cannot change on their own. Another suggestion is that achievement-value dictionary can be created and stored in Cloud Script, which can help for comparison when doing the validation. You may store the dictionary in other places like title data since it won’t change frequently, but will require additional API calls in the cloud script.

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

Kim Strasser avatar image Kim Strasser commented ·

I have difficulties to set up the achievements. I call server.UpdateUserReadOnlyData once(the very first time when the user creates his PlayFab account) to create the achievements in his PlayFab account, but I get an error message. Am I doing something wrong? Is it not possible to have more than 10 entries in Player Data (Title) --> Read Only Data?

I want to create achievements for at least 40 levels.

                    "result": null,
                    "apiError": {
                        "code": 400,
                        "status": "BadRequest",
                        "error": "InvalidParams",
                        "errorCode": 1000,
                        "errorMessage": "Invalid input parameters",
                        "errorHash": null,
                        "errorDetails": {
                            "Data": [
                                "Too many keys specified in Data dictionary update. Limit is 10 and request contained 13."
                            ]
                        }
                    }
0 Likes 0 ·
Seth Du avatar image Seth Du ♦ Kim Strasser commented ·

I think this limit is that you can only update 10 entries for each API call, which means you need send 4 calls for 40. Please navigate to [Game Manger] -> [click setting button on left top corner of web page ] - >[Title Settings] -> [Limits] for more detailed limits information.

0 Likes 0 ·
Kim Strasser avatar image Kim Strasser Seth Du ♦ commented ·

Yes, I found out that this is the problem:

But I have another problem. I need 150-200 Title data key/value pairs for achievements and some player informations like for example the player's country/location. I think I will need especially Read Only Data key/value pairs because I need to create and update the player's achievements.

Which tier should I choose if I need 150-200 Title data key/value pairs? What are the costs per month/year?

0 Likes 0 ·
Show more comments

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.