Saying that it can't use void on line 18 and 42

gist:6189c8745507bb4fce1a890a068d4a91

For some reason, Mono keeps saying that I can’t place “void” by the Update function and for the “state_left_vent”…Plz help…

Hi,

Can you either provide a working link, or, just copy/paste your code into your reply. Thanks :slight_smile:


See also;

You’re missing the closing curly brace from Start()

edit: also it looks like you never fully close the class off. I would suggest focusing on code formatting a bit, it makes it a lot easier to see and find bugs if they layout if consistent and easily read. Yours starts off well but starts to go a bit crazy at the end.

1 Like

You are also missing closing braces on the if statements, basically the same error in multiple places.

When you first start out it can be harder to spot all of the opening/closing brackets and braces, consider using a block format initially, rather than a trailing format and you may find it helps.

Trailing format

public void Start() {

    if(format == "trailing") {
        Debug.Log("Trailing");
    } 
} 

Block format

public void Start() 
{
    if(format == "block") 
    {
        Debug.Log("Block");
    } 
} 

From the above, you can see how it is easier to spot the opening and closing braces because of their indentation.

Hope this helps :slight_smile:

Thanks guys, but I am still having a problem…It is saying that there is an unexpected symbol “end of file” here is a screenshot of my project along with the code too.Capture

You are missing the closing } for the class

Hi Juvan,

Looking at that gist, you don’t appear to have reformatted the braces in an attempt to spot the issue?

The following is a tidied up/reformatted version of your code, no other changes;

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

public class CYOAS : MonoBehaviour 
{
	public Text text;

	private enum States {in_resturant, left_vent, right_vent, partyroom_3, partyroom_4, hallway}
	private States myState;

	// Use this for initialization
	void Start ()
	{
		myState = States.in_resturant;
	}
	
	// Update is called once per frame
	void Update ()	
	{
		print (myState);
		
		if (myState == States.in_resturant) 
		{
			state_in_resturaunt ();
		} 
		else if (myState = States.left_vent) 
		{
			state_left_vent ();
		}
	}

	void state_in_resturaunt ()
	{
		if (Input.GetKeyDown ("space")) 
		{
			text.text = "You are in the new Freddy Fazbear's resturaunt as a security guard. " +
			"You are on your fifth night on the job. Before you begin, your phone rings. " +
			"You can't really hear the person talking, but you know that something is wrong " +
			"and you need to get out. As you know, there is an exit near the Prize Corner. " +
			"Also, you start hearing the noises of machinery activating. The Animatronics. Now, you really need to go. " +
			"There is the left and right Air Vents, and the hallway. Which way do you go?\n\n" +
			"Press L for Left Vent, R for Right Vent, H for Hallway";
			
			if (Input.GetKeyDown ("L")) 
			{
				myState = States.left_vent;
			}
		}
	}
			
	void state_left_vent ()
	{ 
		text.text = "You squeezed into the left vent and finally made it into Partyroom 1. " +
		"You can still hear stomps and whirrs of the animatronics roaming the halls looking " +
		"for you. As you look around the room for some other entrance besides the hallway, a " +
		"loud bang scares you out of your skin. An animatronic is in the room! You kept looking " +
		"frantically and finally found a secret entrance to Partyroom 3. Also, the sound of the " +
		"animatronic sounds like it is really close to that secret entrance, as if it was protecting " +
		"something. What will you do?\n\n" +
		"Press R to go back to the office (if your scared?), P for the secret entrance (and, if there is, " +
		"an item), and H to run for the next Hallway.";
		
		if (Input.GetKeyDown ("L")) 
		{
			myState = States.left_vent;
		}
	}
}    // you didn't add this closing brace

If you following the opening/closing braces from top to bottom you’ll see that you haven’t added the closing brace for the class definition. Martyn mentioned this above.

Hope this helps.

Thanks Rob. I just put the code into Mono and this is what popped up…

I’m not sure what it is saying and I looked back on the code and was very confused…I am sorry if I am giving you guys trouble… :grin:

1 Like

The error code is giving you a handy bit of info but it normally tells you in the most cryptic of ways ha :grin: the last line states “did you mean to use ‘==’ instead?” which suggests you’ve used ‘=’ somewhere that the compiler is expecting to see ‘==’ the most likely cause of this is in an if statement.

Remember a single (’=’) is used for setting a value and for comparing 2 values we use a double (’==’). It looks like the else part of your if statement in the update method only has a single when it’s comparing.

1 Like

It’s in the else if in the Update method. :slight_smile:

It worked Thanks you guys!!

2 Likes

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

Privacy & Terms