Creating a statistic
The first step is to create a statistic definition that includes the main elements for tracking long shots. For our shooter game, we only need one column for the distance of the long shot. The following example shows how to create the statistic definition using the C# SDK.AuthenticationContext: This parameter handles all the authentication behind every request to our services. For a detailed explanation, you can check the following page: Quickstart Statistics.Name: This parameter helps you identify the statistics definition. It’s important to keep something relevant here since it going to be used to make other requests to retrieve informationEntityType: This parameter specifies the type of entity you want to create your statistic for. You can learn more here: Entity Programming Model.VersionConfiguration: This parameter allows you to set a versioning strategy for statistics that reset themselves after a certain period. This concept is covered in depth here: Seasonal Statistics.Columns: Here, we define the number of columns for our statistic, with a maximum of 5 per definition. In this example, we only set one column for the long shots. We also define theAggregationMethodas Max, meaning that the statistic is only going to be updated whenever the new value is greater than the previous one.- The
AggregationMethodhas four possible values:Max: The new value needs to be greater than the previous one.Min: The new value needs to be lower than the previous one.Last: It always updates with the latest value.Sum: The previous and the new value are added together.
- The
Getting a statistic definition
Before adding data to this statistic, we want to ensure that it was created correctly. To do this action, we provide an example of how you can retrieve your statistic definition.Updating a statistic definition
If you want to update your statistic definition, you can do so as follows:Adding data to a statistic
Continuing with our shooter example, we now know how to create a statistic definition, retrieve it, and delete it if necessary. Our next step is to start adding data to our statistic. Keep in mind that these statistics are entity-based statistics, which means the entries are entities. In our specific example, we’re using the entity type title_player_account, so our statistics tracks the information of a player. However, remember that there are other entity types you can use as well. You can check them out here: Available built-in entity types. Now let’s dive into how we can add data to our statistic.Entity: This parameter corresponds to the entity from which we want to make the update of the stat.Statistics: This parameter corresponds to the actual set of statistics of an entity.StatisticUpdate: This parameter corresponds to the statistics values that are going to be added.Scores: This parameter corresponds to the list of scores you can add to one entity. Remember, statistics can have more than one column. You can check these concepts in depth here: Doing More With StatisticsName: This parameter corresponds to the statistic name set when you created the statistic definition.
Retrieving data from a statistic
Let’s do a quick recap. At this point, you created a statistic, checked all the configuration details, and started adding data to it. Now, let’s imagine some players already started using your game, all with impressive long shots. We want to query for one of them. In the following example, we show you how to do this action.Deleting statistics values
Our statistics are working as expected, and we have a bunch of players in your game. However, we start noticing some unusual behavior in the game. So we decided to start fresh and delete the data of our statistic. In the next example, you can see how to data from your statistic.Entity: This parameter is the entity from which you to delete.List<StatisticDelete>: This parameter is a list of the names of the stats you want to delete.
Conclusions
In this tutorial, we learned how to do the following operations:- Create a statistic
- Check the configuration of a statistic
- Update the configuration of a statistic
- Delete the statistic configuration
- Populate the statistic
- Delete entries in the statistic.
