[Solved] Problems with Else If statements and States

I am having trouble understandingwhere I am going wrong. I have completed this video’s instructions, however my program will not run because of multiple errors. When I examine my code, many of my else if statements on lines 20-27 are still in red as if they do not exist, but they change from red to black at random, without me editing my code. Throughout the doc, the color “States” continues to change from black to blue.

I have included a copy of my code, unfortunately none of the color is visible. Would someone mind looking at the text game to see what I am missing?

https://gist.github.com/delaneyharper/135cfdd1fb182a721388cc06d5615c93

Hi @Delaney_Dawn_Harper,

What you have there is a cascade of errors, e.g. one error causing many more.

Chances are there is only actually one issue and once you solve that one the rest will be fine, this is caused by syntax issues typically.

So, lets look at those errors and see what we can see… starting with the first one at the top of the list… it mentions line 52, character 18 - so let’s look there - well, lets look near there anyway…

Line 52 is the else if statement…

void state_cell_mirror() {
	text.text = "You are still in your cell, and you still want to escape. There are " +
				"some dirty sheets on the bed, a mark where the mirror was, " +
				"and that oesky door is still there, and firmly locked.\n\n" +
				"Press S to view the Sheets, or L to view the Lock."
	if (Input.GetKeyDown(KeyCode.S)) 			{myState = States.sheets_1;}
	else if (Input.GetKeyDown(KeyCode.L))		{myState = States.lock_1;}
}

At a first glance nothing jumps out, so I look at the line above, again, nothing jumping out at me… now I’m back to the population of your block of text… oooh… look there’s no ; on the end of the text.text = "" line…

So, rather than either myself or yourself spending anymore time looking for other errors and stressing that we can’t find anything - go ahead an add a semi-colon to the end of that line (before the if statement) and lets see how many of the errors get cleared up :slight_smile:

Thank you, I found another error just like it. The program runs fine now. So when an error pops up, the first number directs you to the line the error is on, and the second number tells you what character?

Great to hear you have got it working, well done :slight_smile:

Yes, that’s correct, however, I would use it as - in the words of Captain Barbosa from Pirates of the Carribean - “more of a guide”… use it to get you to look in the rough area, as you saw, in this case the error was above it, although it errored on the line reported if you see what I mean. :slight_smile:

Okay, I will make sure to keep that in mind. My problem solving skills here are still pretty weak, but that definitely helps.

1 Like

…you said you went ahead and found another similar problem, so well done - that isn’t weak, that is thorough. :slight_smile:

Everyone gets stuck with this type of thing from time to time, so if you find anything else later on thats challenging or doesn’t make sense be sure to post here about it. Not only will you invariably have lots of people willing to help but also there’s a good chance someone else is having the same problem but maybe doesn’t feel comfortable asking about it, so your question could well help a lot of otger people too :slight_smile:

Privacy & Terms