trophy 0
May 2025 20 posts
Sandbox.Services.Stats.Increment : api/Sandbox.Services.Stats/Increment
trophy 0
Apr 2025 2 posts
When Increment() is called, the change is predicted on the client using the following method:

internal void Predict( string name, double amount )
{
	PlayerStat playerStat = Get( name );
	PlayerStat playerStat2 = default( PlayerStat );
	playerStat2.Name = name;
	playerStat2.Title = playerStat.Title;
	playerStat2.Description = playerStat.Description;
	playerStat2.Unit = playerStat.Unit;
	playerStat2.Value = playerStat.Value;
	playerStat2.ValueString = playerStat.ValueString;
	playerStat2.Max = Math.Max( playerStat.Max, amount );
	playerStat2.Min = Math.Min( playerStat.Min, amount );
	playerStat2.Sum = playerStat.Sum + amount;
	playerStat2.Last = DateTime.UtcNow;
	playerStat2.LastValue = amount;
	playerStat2.First = playerStat.First;
	playerStat2.FirstValue = playerStat.FirstValue;
	playerStat = playerStat2;
	stats[name] = playerStat;
}
This allows the front-end (for UI, achievements, etc.) to update without waiting for the new stats to be fetched.

It is worth noting that only the following fields use this prediction:

Sum Max Min LastValue
people
Log in to reply
You can't reply if you're not logged in. That would be crazy.