Hello guys, im trying to add player statistics, when the game ends, i want to get the value what its currently set to so that i can compare the values, lets say in game 1 i reach wave 10, in game 2 i reach wave 9, first i want to check if wave 9 value is greater than the previous one, if it is, i just save the new value as is. if its not, i set the value to the previous one (so the 9 becomes 10) and then save it, so that it will always save the highest value.
however.. when trying to grab the values before they are made, i get an error and the function stops at that point. so it will never save it thus never add the new key.
I get that i cant grab a value of a key that doesnt exist yet, so how can i check if the key exists and if it doesnt, add it manually?
public void OnEndGame() { // When the game ends, get all the playerdata GetPlayerData(); } public void GetPlayerData() { PlayFabClientAPI.GetUserData(new GetUserDataRequest(), OnDataReceived, OnError); } public void OnDataReceived(GetUserDataResult result) { // the current wave the player lost at int tempWave; tempWave = WaveSpawner.currentWave; // highestwavekey = "highestwavemap1" if(result.Data != null && result.Data.ContainsKey(highestWaveKey)) { // setting this string to the previous value, the highest wave the player reached before newHighestWave = result.Data[highestWaveKey].Value; // convert the string to an int int.TryParse(newHighestWave, out highestWave); } // if the current wave is smaller than my previous record, // it will set the current wave int to the previous one, // so that it will always save the highest value if(tempWave < highestWave) { tempWave = highestWave; } // here im saving the new value, if the value is higher than before, it will be the new high score var request = new UpdateUserDataRequest { Data = new Dictionary<string, string> { {highestWaveKey, tempWave.ToString()} // save value } }; PlayFabClientAPI.UpdateUserData(request, OnDataSend, OnError); } ERROR: KeyNotFoundException: The given key 'highestwavemap1' was not present in the dictionary. System.Collections.Generic.Dictionary`2[TKey,TValue].get_Item (TKey key) (at <6073cf49ed704e958b8a66d540dea948>:0)