Getting an error

using UnityEngine;
using System.Collections;

public class NumberWizard : MonoBehaviour {


	void Start () {
		print ("Welcome to Number Wizard");
		print ("Pick a number in your head but don't tell me");
		
		int  max = 1000;
		int  min = 1;
		
		print ("The highest you can pick is " + max);
		print ("The lowest you can pick is " + min);
		
		print ("Is your number higher than 500?");
		print ("Up arrow for higher, down for lower, return for equals");
	}
	
	void Update () {
		if (Input.GetKeyDown(KeyCode.UpArrow)) {
		print ("Up arrow Pressed");
		}
		
		{
		if (Input.GetKeyDown(KeyCode.DownArrow)) {
		print ("Down arrow Pressed");
		}
	}

Assets/Scripts/NumberWizard.cs(30,9): error CS8025: Parsing error

I simply do not understand what I have wrong. I get that it says it’s on line 30 but what is it?

1 Like

I pasted the courses code and it works, so it’s not my program version or my computer, so what did I do wrong here?

	void Start () {
		print ("Welcome to Number Wizard");
		print ("Pick a number in your head, but don't tell me!");
		
		int max = 1000;
		int min = 1;
		
		print ("The highest number you can pick is " + max);
		print ("The lowest number you can pick it " + min);
		
		print ("Is the number higher or lower than 500?");
		print ("Up = higher, down = lower, return = equal");
	}
	
	// Update is called once per frame
	void Update () {
		if (Input.GetKeyDown(KeyCode.UpArrow)) {
			print("Up arrow pressed");
		}
		
		if (Input.GetKeyDown(KeyCode.DownArrow)) {
			print("Down arrow pressed");
		}
	}
}

The correct code ^

Parsing Errors are usually caused by missing or extra brackets. You’ve got an extra { in the Update method in your first code right above the second keycheck which you since removed.

See, I was just looking at it and noticed that myself. Upon noticing I went and took that extra { out of mine and still had an error.

Nevermind, I deleted the space aswell and that fixed it.
Thank you very much for taking the time to reply!

Your first code block as well seems to be missing the last } for the end of the code so if you’ve just copied that back in as is you’ve possibly missed that.

Does every code need 3 of the } at the end?

Hi Dalton,

You may find aligning your braces/brackets in more of a block format initially will help you, as it will make missing ones, or extra ones, often stand out a little more, for example;

private void Start(){
   // ...
}

becomes…

private void Start()
{
    // ...
}

…and if you tab to indent your code also, even with several instances of brackets/braces and can still be useful;

private void Start()
{
    if(name == "Dalton")
    {
        if(surname == "Watson")
        {
            Debug.Log("Hello Dalton Watson!");
        }
    }
}

It’s a little easier for your eye to follow those vertical lines from brace to brace etc.

Hope this is of use :slight_smile:


See also;

2 Likes

Does every code need 3 of the } at the end?

If you open a bracket or a brace, invariably you will need to close it also. Thus, if you open 3, close 3.

1 Like

AH! I think I understand, for every { <= open bracket there has to be a } <= close for it aswell.
Correct?

1 Like

Yes, and the same for brackets; ( and ) :slight_smile:

Except for something like this:
If (Input.GetKeyDown(KeyCode.UpArrow))
^ These have one extra ) on them?
Sorry, having a rough time learning this

1 Like

There’s 2 of each :slight_smile:

if   (   Input.GetKeyDown  (  KeyCode.UpArrow  )   )
2 Likes

Ahhh, I see. Sorry about that. Not sure how I missed it.

1 Like

Easily done, when they are all close together, especially if it’s new to you.

In that nicely spaced out example Martyn displays, you have the if statement which has brackets for it’s condition. The condition is then within those brackets, in this case the test of a key, using Input.GetKeyDown.

The GetKeyDown method takes a parameter, which is passed in its own brackets.

1 Like

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

Privacy & Terms