Hi, According to me the updating of the scoretext should be done in de displayanswer method rather than in the onAnswerSelected method. Since there should also be an update when the player doesn’t select anything and runs out of time.
Don’t know how you’re the only other person that has mentioned this lol
You’re definitely right! But I do assume that it just happens in the OnAnswerSelected method because it is at that point where we update the score and is when we get an input from the player.
Since at this point DisplayAnswer is already incrementing correctAnswers variable, we would need to calculate the score at the end of the DisplayAnswer method to avoid any errors and it could work just fine! But another reason to put it on OnAnswerSelected is so that it is easier to see what is going on step by step
Now, all that said, what if we were deducting points from the score? That would change everything of course, because we would need to then account for that by updating the score when the player either answers incorrectly or does not answer at all!
i got a solution:
Add { scoreText.text = “Score:” + scoreKeeper.CalculateScore() + “%”; } at the end of update method.
void Update()
{
timerImage.fillAmount = timer.fillFraction;
if(timer.loadNextQuestion)
{
hasAnsweredEarly = false;
GetNextQuestion();
timer.loadNextQuestion = false;
}
else if(!hasAnsweredEarly && !timer.isAnsweringQuestion)//answering timevalue ==0
{
DisplayAnswer(-1);
SetButtonState(false);
**scoreText.text = "Score:" + scoreKeeper.CalculateScore() + "%";**
}
}
Thanks for this! This was the last bug I had left and figuring out where to change things was puzzling me.
Since the code you inserted is the same as the code we’re already using in the DisplayAnswer method, I took it one step further by creating a new UpdateScoreText method:
void UpdateScoreText()
{
**scoreText.text = "Score: " + scoreKeeper.CalculateScore() + "%";**
}
And then calling that method in Update and OnAnswerSelected:
public void OnAnswerSelected(int index)
{
hasAnsweredEarly = true;
DisplayAnswer(index);
SetButtonState(false);
timer.CancelTimer();
**UpdateScoreText();**
}
void Update()
{
timerImage.fillAmount = timer.fillFraction;
if (timer.loadNextQuestion)
{
if (progressBar.value == progressBar.maxValue)
{
isComplete = true;
return;
}
hasAnsweredEarly = false;
GetNextQuestion();
timer.loadNextQuestion = false;
}
else if (!hasAnsweredEarly && !timer.isAnsweringQuestion)
{
DisplayAnswer(-1);
SetButtonState(false);
**UpdateScoreText();**
}
}