Max = max+ 1 does not fix your problem based on the lecture

By placing this statement where the lecture tells you, the highest number displayed will be 1001 which does not solve the problem of the script not being able to guess it because it will only reach 1000. To actually fix it the max = max + 1 statement needs to be after printing the highest number you can pick.

3 Likes

…or you could deduct 1 from the number before it’s printed :slight_smile:

1 Like

Alex_Watson is correct. If you deduct 1 from max before it is printed then max would be back to 1000 before Input.GetKeyDown is triggered. You would be right back to the 999 problem. Even if your solution would work, why add extra code when simply moving the increment to a better location would solve your problem? You could use an expression to deduct 1 from max in the print statement

print ("The highest number you can pick is " + (max -1));

2 Likes

I don’t know if this is cheating or best practice, but I just put max = max + 1 after the string telling the player what the max is inside void start. So:

void StartGame () {

	print ("Welcome to NumberWizard! *wooooo* In this game you pick a number between " + min + " and " + max
			+ " and the NumberWizard will find it for you! Get ready to have you mind blown!");

	print ("Is the number higher or lower then " + guess + "?" + 
	" Press up arrow for higher, down arrow for lower or return for an equal number.");

		max = max + 1;

		}
1 Like

I did it similar to Crash370 and it works as expected.

    void StartGame()
{
    // Define variables for Minimum and Maximum guess values
    minGuess = 1;
    maxGuess = 1000;

    // AI guessing methods
    currentGuess = 500;

    // Methods to welcome the player
    print("Welcome to Number Wizard \n");
    print("Pick a number in your head, don't tell me!");

    // Tell player the rules
    print("The smallest number you can guess is " + minGuess);
    print("The largest number you can guess is " + maxGuess);

    // Take a guess and then ask the player to give hint
    print("Is the number higher or lower than " + currentGuess);
    print("Up cursor key for higher, down for lower or RETURN for equal");

    // Add 1 to the maxGuess to prevent guessing being stuck at 999
    maxGuess = maxGuess + 1;
}
3 Likes

Privacy & Terms