[Solved] Parsing error for Prison game

I’m having a parsing error that keeps coming up on the last line. I can’t seem to find what I’m missing. I’ve removed all the code after void update but I still get the error. What am I doing wrong?

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

public class TextController : MonoBehaviour {

    	public Text text;
    	
    		private enum States {cell, cell_1, mirror, sheets_0, lock_0, cell_mirror, sheets_1, lock_1, freedom};
    		private States myState;
    	
    	// Use this for initialization
    		void Start () {
    		myState = States.cell;
    		}
    	
    	// Update is called once per frame
    		void Update () {
    			print (myState);
    			if (myState == States.cell)	{state_cell ();} 
    			else if (myState == States.sheets_0)	{state_sheets_0();} 
    			else if (myState == States.cell_1)		{state_cell_1();} 
    			else if (myState == States.mirror)		{state_mirror();} 
    			else if (myState == States.lock_0)		{state_lock_0();} 
    			else if (myState == States.cell_mirror)	{state_cell_mirror();} 
    			else if (myState == States.sheets_1)	{state_sheets_1();} 
    			else if (myState == States.lock_1)		{state_lock_1();} 
    			else if (myState == States.freedom)		{state_freedom();}
    		}
    		void state_cell () {
    			text.text = "Some days, it's not worth getting out of bed and today is certainly one." +
    						"You were on your way to the store to get the latest console game when " +
    						"suddenly, you were apprehended by the police for 'trespassing on " +
    						"forbidden grounds'. Maybe that shortcut through the mayor's bedroom " +
    						"wasn't the best idea. So now, here you are, stuck in some unknown " +
    						"facility waiting on who knows what. It's been two hours and no one " +
    						"has come. Time to escape.\n\n" +
    						"Looking around, you see a cot with dirty sheets (C), a mirror (M), " +
    						"and a door locked from the outside (D).\n\n" +
    						"What do you want to look at?";
    			if (Input.GetKeyDown(KeyCode.C))		{myState = States.sheets_0;} 
    			else if (Input.GetKeyDown(KeyCode.M))	{myState = States.mirror;} 
    			else if (Input.GetKeyDown(KeyCode.D))	{myState = States.lock_0;}
    		}
    	void state_sheets_0 () {
    			text.text = "This is your cot but I wouldn't recommend sleeping on it. That color of " +
    						"yellow doesn't get there by people just sleeping on it. The less you " +
    						"think about it the, the better.\n\n" +
    						"Press (R) to return.";
    			if (Input.GetKeyDown(KeyCode.R))	{myState = States.cell_1;}
    		}
    	void state_cell_1 () {
    			text.text = "Home, sweet home. At least until you break out of here.\n\n" +
    						"You see a cot with dirty sheets (C), a mirror (M), " +
    						"and a door locked from the outside (D).\n\n" +
    						"What do you want to look at?";
    			if (Input.GetKeyDown(KeyCode.C))		{myState = States.sheets_0;} 
    			else if (Input.GetKeyDown(KeyCode.M))	{myState = States.mirror;} 
    			else if (Input.GetKeyDown(KeyCode.D))	{myState = States.lock_0;}
    		}

The class is missing a closing curly brace }

I see that now and I realize why I didn’t fix it on my initial (and secondary, and tertiary, etc.) run though. I created the states in anticipation of defining them later. So when I closed that, more errors came up because they weren’t defined.

Live and learn.

1 Like

That’s the spirit.

To be fair this is fairly common, a missing curly brace or a missing semi-colon etc, what you’ll probably find now though is that when you next write a bit of code you’ll be super careful and watching really closely to ensure you haven’t missed any braces/brackets! :slight_smile:

I can’t remember whether MonoDevelop does it, but Visual Studio does highlight the brackets / braces if you click on them, e.g. it will highlight its partner. Quite useful. Syntax highlighting I think it’s called. If MonoDevelop doesn’t do that, Visual Studio can be obtained for free from Microsoft, they provide a Community Edition.

Hope this is of use.

p.s. Sorry if my initial reply was a bit short, wasn’t intentionally trying to be rude, was just heading out of the door to go to hospital so didn’t have as much time as usual. :slight_smile:

You’re fine. A prod in the right direction is more useful than a long winded explanation :slight_smile:

1 Like

Privacy & Terms