I Don't Know What I Am Doing Wrong

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

public class TextController : MonoBehaviour {

public Text text;

private enum States {cell, 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.lock_0) {
		state_lock_0();
}			
	

void state_cell () {
		text.text = "You are in prison, you must escape, the door is locked, no windows no holes in the ground, " +
					"Only a bed with dirty sheets, some kind of lock and a dirty mirror, what will you do?\n\n" +
					"Press S to view Sheets, M to view Mirror, L to view Lock" ;
		if (Input.GetKeyDown(KeyCode.S)) 		{myState = States.sheets_0;}
		else if (Input.GetKeyDown(KeyCode.L)) 	{myState = States.lock_0;}			
}

void state_sheets_0 () {
		text.text = "You cant believe you sleep in those things, Its time someone changed them " +
					"the pleasure of prison life, I guess!\n\n" +
					"Press R to return to roaming in your cell" ;
		if (Input.GetKeyDown(KeyCode.R)) 		{myState = States.cell;}			
}

void state_lock_0 () {
	text.text = "You are in prison, you must escape, the door is locked, no windows no holes in the ground, " +
				"Only a bed with dirty sheets, some kind of lock and a dirty mirror, what will you do?\n\n" +
				"Press S to view Sheets, M to view Mirror, L to view Lock" ;
	if (Input.GetKeyDown(KeyCode.R)) 		{myState = States.cell;}			
}

}

Its not letting me start the game any more, when it did the l letter didn’t switch states

Hi,

You’re Update method is missing a closing brace.

If I reformat it below it should make it more obvious;

// 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.lock_0) 
    {
        state_lock_0();
    // you have a missing closing brace here
}
1 Like

thanks bro helped out!

1 Like

You’re welcome :slight_smile:

I’ll be honest - Ben’s a great teacher and all, but his habit of putting the opening brace on the same line as the definition is really confusing - sticking braces under the first letter of the name makes it a lot easier to see which braces go with which.
I realise that his point is to get us used to the style of some coders, but I just wonder if he’s doing it too early in the teaching process…

1 Like

Hi Andrew,

This is actually the default behaviour of the editor, rather than a specific behaviour of Ben I believe.

You can edit the templates that are used by both MonoDevelop or Visual Studio so that new classes are created in the format you prefer, and certainly Visual Studio provides configuration options to enable you to specify how you want your code to be displayed.

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

Privacy & Terms