Facepunch.Steamworks icon indicating copy to clipboard operation
Facepunch.Steamworks copied to clipboard

How are the "async" methods implemented?

Open JeReT opened this issue 1 year ago • 1 comments

For example in StoreStats, the documentation tells:

This function returns true upon success if : RequestCurrentStats has completed and successfully returned its callback AND the current game has stats associated with it in the Steamworks Partner backend, and those stats are published.

I wonder how this is implemented... As the return type is bool I assume this is all blocking the main thread until the result is retrieved... I would have expected async Task<bool> as return type or a callback informing me, when the request is handled...

For RequestCurrentStats the documentation indicates that this happens asynchronuously. I assume that OnUserStatsReceived is called when it finishes, but I couldn't find this info in the documentation. Also, it is unclear what the bool represents which is returned by the method...

Hope somebody can enlighten me.

JeReT avatar Jul 07 '23 15:07 JeReT

hello you can run RequestGlobalStatsAsync AFTER 1) StoreStats, 2) RequestCurrentStats, you will get :

Task<Result> OK indicates success, InvalidState means you need to call RequestCurrentStats first, Fail means the remote call failed

you can probably bind this callback to a function also which is called when a stat has changed : Static event Action<SteamId, Result> OnUserStatsReceived

this is how i monitored stats etc, for example i have another callback for achievements private void Awake() { // do your steam client init in start Steamworks.SteamUserStats.OnAchievementProgress += AchievementChanged; }

private void AchievementChanged(Steamworks.Data.Achievement achievementSatus, int currentProgress, int progress) { if (achievementSatus.State) { Debug.Log($"{achievementSatus.Name} WAS UNLOCKED!"); } }

the same logic will allow you to watch state of your stats

exiledgamesstudio avatar Jul 23 '23 12:07 exiledgamesstudio