This function permits you to set an average statistic type with a "sliding window" effect on the average. The "session_count" value is the current value that you wish to average out, while the "session_length" is the amount of game time since the last call to the function. Please see the

extended Examplebelow for further details on how this can be used.

steam_set_stat_avg_rate(stat_name, session_count, session_length);

Argument | Description |
---|---|

stat_name | The name of the statistic to set (a string). |

session_count | The value to get the average of (a real number) |

session_length | The time that has been taken since the last time the stat was set (a real number). |

N/A

Since the average stat function can be complex to understand, we will illustrate its use with the following example. Consider the case where you'd like to track an average statistic, such as "Points earned per hour". One approach would be to have two stats: an

integerstat, "TotalPoints", and afloatstat "TotalPlayTimeHours", and then divide the total points by the total time to get the "Points per Hour" value.However, once the player has accumulated a significant amount of playtime, the calculated average will change extremely slowly, and the more the user plays the game, the less responsive that average will be. If the user has spent 100 hours playing the game, the calculated average will "lag" by about 50 hours of that, and if they increase their skill, they will not see the increase in "Points Per Hour" that they expect. To get around that we can use a "sliding window" to only calculate the "Points per hour" for the last 10 hours played.

So, to use this function, we would need to create a Steam stat (in the control panel for the game on the Workshop) called "AvgPointsPerHour" and set its

Windowproperty to 10. Now in your game you would have to add some global variables into an instance at the start:

global.Points = 0;

global.Time = 0;

You would then have some controller object to count up the global "Time" variable in an alarm (for example) every second, while your game-play would affect the global "Points" variable. At regular intervals while playing (again, in a controller object, perhaps in an Alarm, or at intervals from polling the "Time" value) you would set the stat like this:

steam_set_stat_avg_rate("AvgPointsPerHour",
global.Points, (global.Time / 3600));

global.Points = 0;

global.Time = 0;

Note that we divide time by 3600 since we want the time in

hoursand not in seconds, and afterward we reset the global "Points" variable and the global "Time" variable to 0 so that the next time the function is called, we get a new average for the statistic. Now, what Steam will do is take this value that you have sent and create an average value over the time that was set for our "window".