Some int-eresting behavior

I’ve finished NumberWizard but notice some odd behavior in the script. Namely, when I redefine min, max and guess in StartGame, guess can’t have “int” in front of it. Let me show you the code-

void StartGame()
    int max = 100;
    int min = 1;
     guess = 500;

Only “guess” throws an error; why is that?


Probably because you have already declared it at the top of the class, and you would be effectively trying to redclare it.

You will want min, max and guess available to your methods in this class, so you should declare them outside of the methods but within the class, then just initialise them with values in the StartGame method.

Hope this helps :slight_smile:

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

Privacy & Terms