From 0b7a2b31be665d478eec1c6f96007a7dd567f237 Mon Sep 17 00:00:00 2001 From: Adrian Miasik Date: Thu, 5 Jan 2023 15:34:41 -0500 Subject: [PATCH] Fix Steamworks null ref bug - Check if client has been initialized/validated prior to running Steamworks logic --- .../Core/Containers/TomatoCounter.cs | 48 ++++++++++--------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/UnityPomodoro/Assets/AdrianMiasik/Scripts/Components/Core/Containers/TomatoCounter.cs b/UnityPomodoro/Assets/AdrianMiasik/Scripts/Components/Core/Containers/TomatoCounter.cs index 6ed9f6f7..b0bf2e22 100644 --- a/UnityPomodoro/Assets/AdrianMiasik/Scripts/Components/Core/Containers/TomatoCounter.cs +++ b/UnityPomodoro/Assets/AdrianMiasik/Scripts/Components/Core/Containers/TomatoCounter.cs @@ -155,30 +155,34 @@ public void SetHorizontalScale(Vector3 newScale) public void ConsumeTomatoes() { #if !UNITY_ANDROID - // CANNED ACHIEVEMENT - // Add discarded pomodoro/tomato to User Stats - SteamUserStats.AddStat("pomodoros_disposed", completedTomatoes.Count); - SteamUserStats.StoreStats(); - - // Fetch canned achievement - Achievement ach = new("ACH_CANNED"); - - // If achievement is not unlocked... - if (!ach.State) + // Check if steam client is found... + if (SteamClient.IsValid) { - // Fetch progression - int pomodorosDiscarded = SteamUserStats.GetStatInt("pomodoros_disposed"); - - if (pomodorosDiscarded >= 8) - { - ach.Trigger(); - Debug.Log("Steam Achievement Unlocked! 'Canned for L8R: Dispose of 8" + - " pomodoros/tomatoes..'"); - } - else if (pomodorosDiscarded != 0) + // CANNED ACHIEVEMENT + // Add discarded pomodoro/tomato to User Stats + SteamUserStats.AddStat("pomodoros_disposed", completedTomatoes.Count); + SteamUserStats.StoreStats(); + + // Fetch canned achievement + Achievement ach = new("ACH_CANNED"); + + // If achievement is not unlocked... + if (!ach.State) { - // Display progress every time we discard - SteamUserStats.IndicateAchievementProgress(ach.Identifier, pomodorosDiscarded, 8); + // Fetch progression + int pomodorosDiscarded = SteamUserStats.GetStatInt("pomodoros_disposed"); + + if (pomodorosDiscarded >= 8) + { + ach.Trigger(); + Debug.Log("Steam Achievement Unlocked! 'Canned for L8R: Dispose of 8" + + " pomodoros/tomatoes..'"); + } + else if (pomodorosDiscarded != 0) + { + // Display progress every time we discard + SteamUserStats.IndicateAchievementProgress(ach.Identifier, pomodorosDiscarded, 8); + } } } #endif