Update bool "isComplete" when time runs out for last question

Hello, I don’t know if anybody has mentioned this issue before, but if you update the boolean “isComplete” only in the method “OnAnswerSelected” like in the video, then it won’t be updated if you just select nothing and wait until time runs out. The issue is not obvious except when you select nothing for the last question, where you can see that “isComplete” is not updated to have a value of true.

My solution is to create a method to update the boolean “isComplete”:

    void UpdateCompleteStatus() {
        if (progressBar.value == progressBar.maxValue)
        {
            isComplete = true;
        }
    }

and call it both when an answer is selected or when time is up:

    public void OnAnswerSelected(int index)
    {
        hasAnsweredEarly = true;
        DisplayAnswer(index);
        SetButtonState(false);
        timer.CancelTimer();
        UpdateScoreText();
        UpdateCompleteStatus();
    }
    void Update()
    {
        timerImage.fillAmount = timer.fillFraction;
        if (timer.loadNextQuestion)
        {
            hasAnsweredEarly = false;
            GetNextQuestion();
            timer.loadNextQuestion = false;
        }
        else if (!hasAnsweredEarly && !timer.isAnsweringQuestion)
        {
            DisplayAnswer(-1);
            SetButtonState(false);
            UpdateScoreText();
            UpdateCompleteStatus();
        }
    }

A similar issue also happens in a previous lecture when the code in the video only updates the score text when an answer is selected and not when time runs out. I hope these issues can be addressed in the videos, or we should bear in mind that the lectures do not always give a compete correct solution and we will need more careful debugging ourselves.

Hi kosumosu,

Welcome to our community! :slight_smile:

To be honest, I currently don’t know if Gary addresses this particular problem but he definitely fixes a few bugs in his videos. However, it is generally advisable to think for yourself because our instructors are humans. Humans make mistakes. While they tested their games and aim to remove all bugs, there is always a chance that bugs still exist.

Personally, I would recommend to debug problems yourself if possible. If you encounter a potential problem in your game, try to analyse it. This will help you develop crucial skills you need for your future games because you will encounter bugs in your future games, and you will have to debug them yourself.

Of course, if you are stuck with the content of our active courses, you may ask us for help. If you hadn’t solved this problem yourself, I would have taken a look into it.

Thanks for sharing your solution! :slight_smile:

1 Like

Just an update from Video 67 (2 videos later):
Gary moved the code to update “isComplete” to when checking whether to load next question in Update() so that the answer screen for the last question is not skipped. This fixed the issue mentioned above. And so I changed my code accordingly:

    void Update()
    {
        timerImage.fillAmount = timer.fillFraction;
        if (timer.loadNextQuestion)
        {
            UpdateCompleteStatus();
            hasAnsweredEarly = false;
            GetNextQuestion();
            timer.loadNextQuestion = false;
        }
        else if (!hasAnsweredEarly && !timer.isAnsweringQuestion)
        {
            DisplayAnswer(-1);
            SetButtonState(false);
            UpdateScoreText();
        }
    }

I’ll leave this post here in Video 65’s discussion just in case anyone encounters this issue and gets confused at this point.

Thanks a lot for sharing the solution, and the reminder that the solution exists! :slight_smile:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.