Max = Max + 1 compiling issue

In section 2 lecture 20 around the 8 minute mark:

After adding in the code for rounding purposes

Max = Max + 1;

Unity states “All compiler errors have to be fixed before you can enter playmode!”

Can anyone tell me what I am doing wrong? I followed the lecture video exactly.

Here is the code:

text 1.12 KB

using UnityEngine;
using System.Collections;
 
public class NumberWizard : MonoBehaviour {
    // Use this for Initialization
   
    int max = 1000;
    int min = 1;
    int guess = 500;
   
 
 
    // Use this for initialization
    void Start () {
        max = max + 1;        // ADDED THIS CODE IN and now have issues
       
        print ("Welcome to Number Wizard");
        print ("Pick a number in your head, dont tell me!");
       
        int max = 1000;
        int min = 1;
       
        print ("The highest number you can pick is "    + max);
        print ("The lowest number you can pick is "     + min);
       
       
       
        print ("Is the number higher or lower than " + guess);
        print ("Up = higher, down = lower, return = equal");
       
       
    }
   
    // Update is called once per frame
    void Update () {
        if (Input.GetKeyDown(KeyCode.UpArrow))  {
            //print("Up arrow pressed");
            min = guess;
            guess = (max + min) / 2;    
            print ("Higher or lower than " + guess);       
        } else if (Input.GetKeyDown(KeyCode.DownArrow)) {
            //print("Down arrow pressed");
            max = guess;
            guess = (max + min) / 2;    
            print ("Higher or lower than " + guess);
        } else if (Input.GetKeyDown(KeyCode.Return))    {
            print ("I won!");
        }
    }
}

Helo Mike, how are you?

You have declared max and min two times. Remove the “int” keyword from the “int max = 1000;” and “int min =1;” inside the Start() method and you should be ready to go :slight_smile:

Hi Joao,

I am good thank you for this. I’m not sure how I missed this… It does make since now to remove the “Int” lines.

Thank you so much!

No problem!

Actually it would be better to remove just the “int” keyword and keep the “max = 1000” and “min = 1”, otherwise when you restart the game it will keep the last match’s values

Privacy & Terms