Updating the scoreText

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.

3 Likes

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 :wink:

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() + "%";**

    }

}