Parsing error

Hi,

In section 20, I received an error message saying parsing error. What did i do wrong?

using UnityEngine;
using System.Collections;

public class NumberWizard : MonoBehaviour {

	// Use this for initialization
	int max = 1000;
	int min = 1;
	int guess = 500;
	
	void Start () {
		print ("Welcome To Number Wizard");
		print ("Pick A Number In Your Head, But Don't Tell Me!");
		
		
		
		print ("The Highest Number You Can Pick Is " +max);
		print ("The Highest Number You Can Pick Is " +min);
		
		print ("Is The Number Higher Or Lower Then  " +guess);
		print ("Up = Higher, Down = Lower, Return = Equal");
	}
	
	// Update is called once per frame
	void Update () {
		if (Input.GetKeyDown(KeyCode.UpArrow)) {
			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");
	}
}

Your last else if is missing a closing }.


See also;

1 Like

Hello, I’m willing to help you but some Print-Screens could be helpful. Where the error appears? Inside Unity or in Monodevelop? Did you try to save the file? Did you try to “build” (by pressing F8) your script? If you try to “build” your script, Monodevelop will show your where the error occurs!

Pffff… Ι checked for the brackets but didn’t see that! :confused: Last else if was tricky! :stuck_out_tongue:

1 Like

That’s why having the code formatted in the posts on the forum is so helpful (and why I editted the post).

thank you so much i didn’t realize that :slight_smile:

1 Like

You’re more than welcome :slight_smile:

Also why I prefer using the other bracket style:

class whatever
{
public void whoever
{
blah blah blah
}
}

Keeps it more tree-like. And who cares about using more whitespace?

Comments and white space shouldn’t really be part of the equation with C# anyway, it all gets stripped out when it’s compiled.

In addition, if you use a decent editor (Visual Studio for example), they often come with tools built in which will help you identify which brackets belongs to which, along with other niceties like seeing if any of your variables are not actually being used and so on. :slight_smile:

Privacy & Terms