Coding Error
So I've been working on a text based game and I just finished writing out the code. I have two current errors in my code. One is CS1525 unexpected symbol '{' which is on line 85. The next error has two occurrences in the code. It is CS0116 a namespace can only contain types and namespace declarations. there is one error on line 89 and 98.
If anyone could help me i'd really appreciate it :D
My code is here:
using UnityEngine; using UnityEngine.UI; using System.Collections;
public class TextController : MonoBehaviour {
public Text text;
private enum States {boat, cabin_0, atf, button, cabin_1, key, ulb, lifeboat};
public States myState;
// Use this for initialization
void Start () {
myState = States.boat;
}
// Update is called once per frame
void Update () {
print (myState);
if (myState == States.boat) {state_boat();}
else if (myState == States.cabin_0) {state_cabin_0();}
else if (myState == States.atf) {state_atf();}
else if (myState == States.button) {state_button();}
else if (myState == States.cabin_1) {state_cabin_1();}
else if (myState == States.key) {state_key();}
else if (myState == States.ulb) {state_ulb();}
else if (myState == States.lifeboat) {state_lifeboat();}
}
void state_boat () {
text.text = "You are on your boat and all you remember was a sudden bang. You look towords " +
"the cabin of the boat only to see it filling with more water by the second. " +
"You know that there is a lifeboat on the boat but you need to find out how to " +
"activate it.\n\n" +
"Press C to look further into the cabin, A to look around the front of the boat and B to " +
"investigate the lifeboat button.";
if (Input.GetKeyDown(KeyCode.C)) {myState = States.cabin_0;}
else if (Input.GetKeyDown(KeyCode.A)) {myState = States.atf;}
else if (Input.GetKeyDown(KeyCode.B)) {myState = States.button;}
}
void state_cabin_0 () {
text.text = "You walk into the cabin as water gushes through the hole in the hull " +
"You notice that there is a sign that states 'Lifeboat button outside (requires key) " +
"\n\n" +
"Press R to return to the deck of the boat";
if (Input.GetKeyDown(KeyCode.R)) {myState = States.boat;}
}
void state_atf () {
text.text = "You walk around the side of the boad to notice what you have hit, you hit a rock which teared " +
"right through the hull. You also notice a lot of junk here with a chest at the end of the boat. " +
"\n\n" +
"Press L too Look into the chest, press R to return ot the deck of the boat";
if (Input.GetKeyDown(KeyCode.L)) {myState = States.key;}
else if (Input.GetKeyDown (KeyCode.R)) {myState = States.boat;}
}
void state_button() {
text.text = "You walk over to the end of the boat and notice that there is a button that is locked over by a cover. " +
"It is the button to activate the lifeboat, the only problem is you need to find the key somewhere. " +
"I hope that it didnt fall off the edge!\n\n" +
"Press R to return ot the deck of the boat";
if (Input.GetKeyDown (KeyCode.R)) {myState = States.boat;}
}
void state_cabin_1() {
text.text = "You walk back into the cabin to find that the water is now reaching your knee, you need to act fast and " +
"get that lifeboat on the water before the boat goes under! " +
"\n\n" +
"Press R to return to the crate around the front of the boat";
if (Input.GetKeyDown (KeyCode.R)) {myState = States.key;}
}
void state_key() {
text.text = "You open the lid of the crate and theres boxes everywhere you pick out one box in particular the box says" +
" 'USE ONLY IN AN EMERGENCY' You crack it open and find the key to the lifeboat button as well as some first aid and flares " +
"\n\n" +
"Press C to look in the cabin again, press B to go to the unlock Button";
if (Input.GetKeyDown(KeyCode.C)) {myState = States.cabin_1;}
else if (Input.GetKeyDown(KeyCode.B) {myState = States.ulb;}
}
void state_ulb () {
text.text = "You run down the side of the boat, you get the key out of your pocket and insert it into the key slot and turn it. " +
"You feel a sense of relief as it unlocks the lid of the button. " +
"\n\n" +
"Press L activate the Lifeboat";
if (Input.GetKeyDown (KeyCode.L)) {myState = States.lifeboat;}
}
void state_lifeboat () {
text.text = "You hit the button and you can see the lifeboat fall out the side of the boat you feel reallt happy and you jump into the boat and paddle away" +
"\n\n" +
"Press R to restart the game you won :D";
if (Input.GetKeyDown (KeyCode.R)) {myState = States.boat;}
}
Answer by UsmanAbbasi · Jan 18, 2016 at 06:55 AM
"CS1525 unexpected symbol '{' " this error is causing next 2 errors. If you resolve this you will get rid of other two errors also. You are missing "}" somewhere or you have an additional "{" somewhere. Your code is not indented properly which is making it difficult for me to look for missing braces. Indent it properly and then repost it so people can help you.
Your answer
