Not sure why I have an error

Hello!

I’ve written an original story as part of the challenge. It wasn’t really that hard…considering I just edited/changed/added a lot the code Ben used. (I mention this as this may be a possible reason for my error.)

Anywho, for some reason I’m getting errors at this part and not anywhere else. I checked and I don’t think I see anything that’s causing this problem. Perhaps one of you may see something I’m missing?

Here’s a picture of the code (or at least a pic of the part I’m having errors:

Thank you!

Hi,

You are missing the closing quotes in the text block wothin the Update method, just before the semi-colon.

It is typically best to copy/paste your code into your posts and apply the code formatting, this way those trying to help you can see all of the code and may even be able to copy/paste an example for you.

Hope this helps. :slight_smile:


See also;

1 Like

I just realized I didn’t even really need that line of code anyways (at least up there). However, still doesn’t work. Thank you for the tip of posting the code here! Here’s the code. This is driving me mad!

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

public class TextController : MonoBehaviour {
	
	public Text text;
	
			// Use this for initialization
			    
	private enum States {courtroom_1, objection, courtroom_2, g_court, b_court, con_court, guilty, N_G, guilty_2};
		private States myState;
	   
		    // Use this for initialization
	void Start () {
			    myState = States.courtroom_1;
	}
	
	// Update is called once per frame
	void Update () {
				
				print (myState);
				if (myState == States.courtroom_1) 		{state_courtroom_1();}
				else if (myState == States.objection) 	{state_objection();}
				else if (myState == States.courtroom_2) {state_courtroom_2();}
				else if (myState == States.g_court) 	{state_g_court();}
				else if (myState == States.N_G) 		{state_N_G();}
				else if (myState == States.con_court) 	{state_con_court();}
				else if (myState == States.b_court) 	{state_b_court();}
				else if (myState == States.guilty) 		{state_guilty();}
				else if (myState == States.guilty_2) 	{state_guilty_2();}
	}
		
		void courtroom_1 () {
				text.text = "You have died. Instead of going to heaven or hell (right away) you appear  " +
										"in a courtroom. An angel and demon are here to judge your actions throughtout " +
											"your life. Unfortunately, the demon judge is corrupt (and gets away with it a lot) " +
											"and immediately tries to declare you guilty. Do you object? \n\n" +
											" Press O to object or S to stay silent." ;
				if (Input.GetKeyDown(KeyCode.O)) 		{myState = States.objection;}
				else if (Input.GetKeyDown(KeyCode.S)) 	{myState = States.guilty;}
		    }
	    
		void state_objection() {
				text.text = "You make an objection! You try to argue for a fair trial. But the demon judge " +
							"insists on convicting you. Both judges ask if you have something that'll make " +
							"reconsider their verdict. You have a piece of evidence that could be really good " +
							"but it could be bad depending on their reaction. Do you present it?. \n\n" + 
								"Press E to mention evidence or C to conceal it." ;
				if (Input.GetKeyDown(KeyCode.E)) 		{myState = States.courtroom_2;}
				else if (Input.GetKeyDown(KeyCode.C)) 	{myState = States.con_court;}
		    }
	    
		void state_courtroom_2() {
				text.text = "You mention the charity work you've done throughout the years. The angel judge  " +
								"nods his head while the demon one shakes his. It looks like it worked.  " +
									"The judges say that they'll spin a wheel consisted of names of close friends  " +
									"and family and whatever name the arrow lands on, you can call the person as a " +
									"witness. This will help their decision, they claim. They spin the wheel, and it " +
									"unluckily lands on your aunt. She hates your guts and will no doubt mention your " +
									"bad pass life, which may be bad for you. Then again...you haven't seen her in years. Maybe she " +
									"had a change of heart? \n\n" +
									"W to call her or N to not call a witness.";
				if (Input.GetKeyDown(KeyCode.W)) 		{myState = States.b_court;}
				else if (Input.GetKeyDown(KeyCode.N)) 	{myState = States.g_court;}
		    }
	   
	    void state_g_court() {
				text.text = "Both judges simply nod. The demon pulls out a file and mentions something damning. " +
								"In your past life, you were a drunk and drug addict. You even murderered a man " +
									"and suffered serious jailtime. While you did clean yourself up after release " +
									"the demon asks that if your recent good actions should erase your bad actions " +
									"and earn you a spot in Heaven. A verdict will be delivered depending on your answer. \n\n" +
									"S to give a sappy speach or A to agree and accept your fate." 
		        if (Input.GetKeyDown(KeyCode.S)) 		{myState = States.N_G;}
		        else if (Input.GetKeyDown(KeyCode.A)) 	{myState = States_guilty;}
		    }
	    
		void state_N_G() {
				text.text = "The speech was sappy. I mean REALLY sappy...but the angel seemed pleased by it " +
								"and deemed you worthy for heaven Congrats!\n\n" +
									"Press P to play again." ;
				if (Input.GetKeyDown(KeyCode.P)) 		{myState = States.courtroom_1;}
		    }
	    
	    void state_con_court() {
				text.text = "You decide not to mention all the charity work you've done. " +
								"The angel disappointingly shakes his head while the devil flashes a grin. \n\n " +
								"The judges say that they'll spin a wheel consisted of names of close friends  " +
									"and family and whatever name the arrow lands on, you can call the person as a " +
									"witness. This will help their decision, they claim. They spin the wheel, and it " +
									"unluckily lands on your aunt. She hates your guts and will no doubt mention your " +
									"bad pass life, which may be bad for you. Then again...you haven't seen her in years. Maybe she " +
									"had a change of heart? \n\n" +
									"W to call her or N to not call a witness."
							
				if (Input.GetKeyDown(KeyCode.W)) 		{myState = States.b_court;}
				else if (Input.GetKeyDown(KeyCode.N)) 	{myState = States.g_court;}
		    }
	    
		void state_b_court() {
				text.text = "It goes just as bad as you expected...maybe even worse. The angel is certainly displeased " +
								"and the demon is certainly pleased.The demon then pulls out a file and mentions something damning. " +
									"In your past life, you were a drunk and drug addict. You even murderered a man " +
									"and suffered serious jailtime. While you did clean yourself up after realease " +
									"the demon asks that if your recent good actions should erase your bad actions " +
									"and earn you a spot in Heaven. A verdict will be delivered depending on your answer. \n\n" +
									"S to give a sappy speach or A to agree and accept your fate." 
				if (Input.GetKeyDown(KeyCode.S)) 		{myState = States.guilty;}
				else if (Input.GetKeyDown(KeyCode.A)) 	{myState = States.guilty;}
		    }
	    
		void state_guilty() {
				text.text = "Sadly, both judges deemed you worthy for Hell. Oh well. We can't win them all. \n\n" +
								"Press P to Play again";
				if (Input.GetKeyDown(KeyCode.P)) 		{myState = States.courtroom_1;}
		    }
		    
		    void state_guilty_2() {
				text.text = "Sadly, even with your sappy speach, both judges deemed you worthy for Hell. Oh well. We can't win them all. \n\n" +
								"Press P to Play again";
				if (Input.GetKeyDown(KeyCode.P)) 		{myState = States.courtroom_1;}
		    }
}

(Hope I did that right.)

Hi,

Have a look at your console, you most likely have a few errors as you currently have three methods in which your story text doesn’t have a semi-colon on the end of the final line. The numbers in the error messages will direct you to a line number.

To get you started, check state_g_court :slight_smile:

I just looked over the code again and found a few more places without semicolons. Then after I fixed that some errors appeared, but I quickly fixed them. Thank you! I wouldn’t have done it without you!

1 Like

That’s often the nature of the beast. Quite often the first error will prevent others from being detected because the compiler cannot make sense of what follows.

Well done on resolving the errors and being able to move forward again :slight_smile:

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

Privacy & Terms