fix: (hopefully) i create a new voter list if it's empty instead of null ref

This commit is contained in:
Fangh 2024-01-29 21:34:39 +01:00
parent f379a3d5c8
commit 6840171608

View File

@ -494,12 +494,17 @@ private void OnCurrentQuestionChanged(object sender, ValueChangedEventArgs onlin
/// <param name="propositionNumber"></param>
public void OnClickProposition(int propositionNumber)
{
/*
Debug.Log($"Room has {myRoom.questions.Count} questions. the current Question is Q({myRoom.currentQuestionId}).");
Debug.Log($"Q({myRoom.currentQuestionId}) has {myRoom.questions[myRoom.currentQuestionId].propositions.Count} propositions.");
Debug.Log($"Player click on proposition {propositionNumber}.");
Debug.Log($"it has {myRoom.questions[myRoom.currentQuestionId].propositions[propositionNumber].voters.Count} voters.");
*/
List<string> voters = myRoom.questions[myRoom.currentQuestionId].propositions[propositionNumber].voters;
if(voters == null)
voters = new List<string>();
voters.Add(currentPlayer.id);
myOnlineRoom.Child("questions").Child(myRoom.currentQuestionId.ToString()).Child("propositions").Child(propositionNumber.ToString()).Child("voters").SetValueAsync(voters);