# [Help] When i start the game it adds one to the guess

Hello,

Today i finished the lecture and when i start the game it adds another line that says:

“Higher or lower than 501”

This is the whole code:

using UnityEngine;
using System.Collections;

public class NumberWizards : MonoBehaviour {

// Use this for initialization

int max = 1000;
int min = 1;
int guess = 500;

void Start () {
StartGame();
NextGuess();

}

void StartGame () {
max = max + 1;

print ("Welcome to Number Wizard!");
print ("Pick a number in your head but don't tell me homie");

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

print ("Is the number higher or lower then ?" +guess);
print (" Up arrow = higher,Down = lower, return = equals ");
}

// Update is called once per frame
void Update () {
if (Input.GetKeyDown(KeyCode.UpArrow)){
// print("Up arrow pressed");
min = guess;
NextGuess();
}
else if (Input.GetKeyDown(KeyCode.DownArrow)){
// print ("Down arrrow pressed");
max = guess;
NextGuess();
}
else if (Input.GetKeyDown(KeyCode.Return)){
print ("I won!");
}

}
void NextGuess () {
guess = (max + min) / 2;
print (“Higher or lower than " +guess);
print (” Up arrow = higher,Down = lower, return = equals ");
}
}

and i didn’t even press a key, what is the problam?

Many thanks for the helpers :3

Basically, you’re running NextGuess before any choice is made, so it’s
changing the guess variable to (max+min)/2 (which is (1001+1)/2) and
printing those lines in that function right after it finishes StartGame.

I think i understand so i need to delete NextGuess(); in void Start () becuse it’s printing the lines when the game starts? becuse on the lecture he showed that he has NextGuess(); in the void start so why it didn’t do problam?. and this leads me to another question. Why do i need to type in void start StartGame(); and in void Update nothing ?

void Start
{
Defines a new function.
Then, you’re calling StartGame() from inside the Start function.