Unexpected Symbol Void

So I’ve just started this coding lesson program up again after a couple of months and have had some problems. First off I had a couple of different errors that I’ve been able to solve, but now I only have one that I can’t seem to find the problem with. Can anyone help out?

Hi @Jack_Gray,

The problem is being caused by your curly braces.

The structure should look like this for a class;

public class NumberWizards : MonoBehaviour 
{

} 

As you can see, you have both opening and closing curly braces directly after MonoBehaviour.

The next issue is the Start() method, here you have a closing curly brace instead of an opening one, it should resemble this;

private void Start()
{
    // other code
}

I would urge you to tab in the closing curly braces so that they are inline with the class or method that they are being used for (ref lines 21, 28, 32).

Your Update() method has a closing curly brace in the middle of it, creating a random if statement that doesn’t belong to anything. Remove this closing curly brace on line 28.

At the very end of the script there should be a closing curly brace for the class, as mentioned above.

Hope this helps :slight_smile:


Quick example of a class with empty methods but demonstrating brackets and braces;

public class Jack : MonoBehaviour
{
    private void Start()
    {
        // Jack starts here
        AwesomeTest();
    }

    private void Update()
    {
        Jack updates here
    }

    // example of brackets and braces for an if statement
    private void AwesomeTest()
    {
        bool jackIsAwesome = true;

        if(jackIsAwesome == true)
        {
            Debug.Log("Jack *IS* Awesome");
        }
    }
}

It’s a noddy example but it shows you a clean layout for the brackets and braces. Each opening bracket or brace must have a respective closing one.


Note, you can also paste your code into your posts, rather than dropping the screenshots in, this can be more useful when people try to help you as they can copy and paste parts of your code, rather than having to type it all out.


See also;

Alright, thank you for the explanation on the brackets. I have solved most errors, but now I am getting another one. My error is error CS9010: Primary constructor body is not allowed

And my code is…

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class NumberWizards : MonoBehaviour 
	{
	

	// Use this for initialization
	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 Is " + min);

		print ("Is The Number Higher Or Lower Than 500?");
		print ("Up Arrow for Higher, Down Arrow For Lower, Enter for Equals");

	} 

	// Update is called once per frame
	void Update ()
	{
		if (Input.GetKeyDown (KeyCode.UpArrow))
			print ("Up Arrow Pushed.");
	}


	{
		
	if(Input.GetKeyDown(KeyCode.DownArrow)) 
			print ("Down Arrow Pushed.");
	}
}

Hi,

That last if statement can’t just sit there like that, it needs to be contained within a method, in this specific case, the Update() method.

Remove the two curly braces between the two if statements and that should resolve it, e.g.

	// Update is called once per frame
	void Update ()
	{
		if (Input.GetKeyDown (KeyCode.UpArrow))
			print ("Up Arrow Pushed.");
	} // delete this line


	{ // delete this line
		
	    if(Input.GetKeyDown(KeyCode.DownArrow))  
			print ("Down Arrow Pushed.");
	}

Please check the link I provide you with regards to the code formatting, makes it a little easier to read :slight_smile:

I fixed it, I had to remove the brackets on lines 31 and 34. Thanks for your help anyways!

1 Like

Good stuff, glad you can move forward again :slight_smile:

Privacy & Terms