This topic covers some common scenarios for creating user statistics.
Use this pattern when you want to flag whether the user has met a specific condition in the game logic or not.
| Field | Value |
|---|---|
| Event Name | AchievementUnlocked |
| Event Fields | UnlockId (Data type: INT32) |
| Stat Template Name | AchievementUnlocked.UnlockId |
| Operator | REPLACE |
| Parameter | 1 |
| Access | Open |
Apply the REPLACE operator with a literal value of “1” if the flag must be read as TRUE.
Apply the SUM operator with a literal value of “1” if the flag must be equal or greater than 1 to trigger the game logic.
If necessary, remember to initialize or reset the value for REPLACE boolean stats; otherwise the most recently set value will be persisted.
In some cases it is convenient to define an event that allows resetting a Boolean stat to FALSE. in those cases, use a REPLACE operation with a literal value of “0”.
Use this pattern when you want to increment the stat value by a fixed or variable amount each time the event is processed.
Example: Counter of multiplayer matches won
| Field | Value |
|---|---|
| Event Name | MatchCompleted |
| Event Field 1 | Result (Data type: INT32) |
| Event Field 2 | Mode (Data type: UNICODE STRING) |
| Stat Template Name | MatchesCompleted.Result.Mode |
| Operator | SUM |
| Parameter | 1 |
| Access | Open |
Apply the SUM operator to the corresponding event field, or specify a fixed constant value as the parameter.
In order to decrement the value of the stat use a negative value as the parameter, either as a fixed constant or as a run-time value in the event field.
Do not use string datatype ‘literal’ values as parameters with the SUM operator.
Do not apply the SUM operator to a string datatype event field.
If you have multiple events updating the same stat, make sure that all the stat rules updating that stat use the same operator.
Use this pattern when you want to persist the largest (MAX) or smallest (MIN) record for the user and discard any values that don’t improve the user’s record.
Example: Fastest time completing any track in the Europe set.
| Field | Value |
|---|---|
| Event Name | TrackCompleted |
| Event Field 1 | TrackSet (Data type: UNICODE STRING) |
| Event Field 2 | TimeInSeconds (Data type: INT32) |
| Stat Template Name | BestFinishTimeInSeconds.TrackSet |
| Operator | MIN |
| Parameter | TimeInSeconds |
| Access | Open |
Apply the MAX or MIN operator to the corresponding event field.
Do not use ‘literal’ values as parameters with the MAX or MIN operator.
Do not apply the MAX or MIN operator to a string datatype event field.
If you have multiple events updating the same stat, make sure that all the stat rules updating that stat use the same operator.
Use this pattern when you want to persist the latest record for the user regardless of whether the value improves the user’s best record or not.
| Field | Value |
|---|---|
| Event Name | TrackCompleted |
| Event Field 1 | TrackId (Data type: INT32) |
| Event Field 2 | TimeInSeconds (Data type: INT32) |
| Stat Template Name | BestFinishTimeInSeconds.TrackId |
| Operator | REPLACE |
| Parameter | TimeInSeconds |
| Access | Open |
Apply the REPLACE operator to the corresponding event field or literal value.
If necessary, remember to initialize or reset the value for REPLACE stats; otherwise the most recently set value will be persisted.