'Max' won't reset to 1000

I’m coming to the end of the Number Wizard module but don’t seem to be getting the results I’d expected.

It all works fine until the game is restarted. The ‘max’ won’t reset to 1000 and seems to be stuck of the ‘guess’ number. I’ve tried moving my integers into ‘Start ()’ and also after the print ‘I WON’ text to see if that would reset them but both just cause me more errors.

LINK TO SCRIPT;
https://gist.github.com/anonymous/2925adf1077853a1d678fc00e946a324

Any suggestions would be appreciated.

Hi Kim,

So, you want to define the integers at the top of the class, so that they are member variables and can be accessed anywhere in the script, but the initialisation of the variables you want to move to where the game begins, in the example below, they are initialised within the StartGame method, which is called from Start.


Example;

public class NumberWizard: MonoBehaviour
{
    int max;
    int min;
    int guess;

    /// <summary>
    /// Initialise
    /// </summary>
    void Start()
    {
        StartGame();
    }

    /// <summary>
    /// Start the game
    /// </summary>
    void StartGame()
    {
        max = 1000;
        min = 1;
        guess = 500;

        // ...
    }

     // ...
}

Hope this helps :slight_smile:

1 Like

Hi @Kim_Mayhew,

Please add [SOLVED], if the above worked.

Perfect! Thank you very much

2 Likes

You’re more than welcome Kim :slight_smile:

Privacy & Terms