nesting if/else [solved]

Started by HandsFree, Fri 29/07/2011 22:24:19

Previous topic - Next topic

HandsFree

I did nested if/else statements before in my RON learning project, but this time I must be overlooking something.
I have this:

function room_AfterFadeIn()
{
 if (cChpaltr.Room == 34){ //Elaine is in church
   if (Game.DoOnceOnly("MeetElaine") == true){
     cChpaltr.Say("Something");
     //do things
   }
   else{ //already talked to Elaine
     cChpaltr.Say("Something else");
     //do more things
   }
 else{ //Elaine not in church
   cLan.Walk(285, cLan.y, eBlock, eAnywhere);
 }
}

I get a parse error at the else-line that says //Elaine not in church.
What am I doing wrong?

thanks

Victor6

Unless I've miscounted (or you've mis-copied), you're missing a closing brace at the end of the function.

TomatoesInTheHead

#2
You have an opening bracket in
"if (cChpaltr.Room == 34){"
that you haven't closed, so a } right before the line where you get the parse error should help.

In general, with your indentation style, check for every if/else that there is a closing bracket at the same indentation level to find such mistakes.

Edit: Victor, no, the function has a closing bracket, it's the inner bracket that's missing.

HandsFree

Ok, thanks.
I keep forgetting that you have to close the if-statement also if there's an else coming.
I used to toy with visual basic where you only close after the last else.

Atelier

HandsFree don't forget you can press Ctrl+B when your cursor is next to a bracket.

This highlights the matching brace in yellow.
If the bracket has no counterpart it's highlighted in red.


SMF spam blocked by CleanTalk