Coding error

So I wanted to change a little bit of coding there, after the game asks, the highest number and the lowest number that you can select is, I wanted the game to ask if the user is ready, so i wrote a code to ask the user if you have thought of the number and asked the user to press leftcontrol if he is ready. The problem that i am facing now is that it works fine for once, but when the game restarts, it stops at the point where the game asks user to press left control.

This is my code:

    int max;
	int min;
	int guess;	
	void Start ()
			{ 
			StartGame ();
			}	
	
	void StartGame() {
	        max=1000;
	        min=1;
	        guess=500;
			
			
			print ("***************************");
			print ("welcome to Numberwizard");
			print ("pick a number in your head but don't tell me");
			
			
			print ("The highest number you can select is " + max);
			print ("The lowest number you can select is " + min);
			print ("press leftcontrol if you have selected");
			max=max+1;
			
		}
		void NextGuess()
		{
		
		guess = (max + min)/2;
		print ("higher or lower than " + guess);
		}
		
		

void Update () {
		if (Input.GetKeyDown(KeyCode.LeftControl))
		{
			print ("Is your number higher or lower than " + guess);
			print ("Up arrow for higher, down for lower, return for equal");
		}
 		if (Input.GetKeyDown(KeyCode.UpArrow))
 		{
 		//print("Up arrow key pressed");
 		min = guess;
 		NextGuess ();
 		
 		}
	    else if (Input.GetKeyDown(KeyCode.DownArrow))
	    {
	    //print("Down arrow key pressd");
	     max = guess;
	     NextGuess ();
	   
	    }
	    else if (Input.GetKeyDown(KeyCode.Return))
	    {
	    print ("I won!");
	    StartGame ();
	    }
	}	
}
1 Like

Hey there. Just tested out the code myself and it looks good at first glance. You problem might not be a coding error as when I ran it I forgot that I had collapse on within the Unity console frame. Make sure you toggle that off to have the lines register every time in sequence. They are still operating properly but collapse makes it unclear since new lines are just added to the tally count for each occurrence. Cheers and keep up the good work!

1 Like

got it, thanks man

2 Likes

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

Privacy & Terms