question

treasure.hunter.dev@gmail.com avatar image
treasure.hunter.dev@gmail.com asked

Title wide counter of game events

I would like to implement a counter that is title wide, not player specific, of the total number of items found by all the players of my game.

I already have a CloudScript method that gets called whenever a player finds an item, so ideally I would just want to increment a counter inside that which can then do something special when a particular count has been reached. I guess the best real-world analogy here would be that of a "millionth customer" promotion.

The first approach I thought of was to read, increment and set an element of Title Data, but since Title Data isn't really intended for often changing values I was wondering if there was a better solution. I'm really looking for something that can be done wholly within PlayFab/CloudScript as I don't want to roll out any custom server functionality just for this one feature.

By way of context, players would not be finding items at a high rate, probably an item every few minutes if they were really trying hard, so maybe updating Title Data would be acceptable?

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

Rick Chen avatar image
Rick Chen answered

Currently there is no global counter feature in PlayFab yet. The approach of updating Title Data may not be a good solution. Even if the players were updating the Title Data in a low rate, there could be a situation that multiple players trying to update the data at the same time, which may cause inaccurate result. For more detail, please refer to this thread: https://community.playfab.com/questions/956/211248347-Writing-Title-Data-in-Cloud-Script.html.

A possible workaround would be:

  1. Generate an event when a player finds an item.
  2. Write an Azure function that use KQL (Kusto Query Language) to query the count of the events generated from step 1. To use the KQL in Azure Function, for example, you could follow this document: Tutorial: Connecting Kusto C# SDK to Insights if you use the C# to write the Azure function.
  3. Create a schedule task that runs the Azure function from step 2 to check the count periodically.
10 |1200

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

treasure.hunter.dev@gmail.com avatar image
treasure.hunter.dev@gmail.com answered

OK, thanks Rick, that certainly sounds like a safer approach that I could use, and as luck would have it I'm currently learning about Azure Functions for implementing password reset.

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.