Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sugarcube 2: Nested If statement problem

Hi! I'm likely doing something terribly wrong, being more a writer than coder, but I do know enough about coding to stay afloat... most of the time. I'm having a problem in a project, with an IF statement that contains another IF statement.
It works fine with this...
<<if $Light eq true>>
  Room Description
  <center>Exit links here</center>
<<else>>
  Dark Room Description
<<endif>>
<center>Always visible exit link here</center>

But as soon as i try to use this...
<<if $Light eq true>>
  Room Description
    <<if $Stat lt 34>>Nothing
    <<elseif $Stat lt 67>>Comment on env. hint
    <<else>>Identified env. hint
    <<endif>>
  <center>Exit links here</center>
<<else>>
  Dark Room Description
    <<if $Stat lt 34>>Nothing
    <<elseif $Stat lt 67>>Comment on env. hint
    <<else>>Identified env. hint
    <<endif>>
<<endif>>
<center>Always visible exit link here</center>

...I get errors popping up that the first IF has no closing statement, or that the Else is on it's own. Is the code seriously thinking that the nested statement's close is the main statement's close as well? The nested parts are working fine...

Comments

  • I just tested it and it seemed to work. I don't see anything wrong, though the <<if>> is already set to check for true, so you can shorten <<if $Light eq true>> to <<if $Light>> and get the exact same result.

    I attached the html file I had, it uses your code exactly as you've written it. What's it doing wrong?

  • edited February 2017
    Specifically, if i have one IF statement inside of another one, it treats the nested IF as ending both the nested IF and the 1st level IF. The file you posted is doing exactly what i WANTED it to, so i can only surmise that I MUST be screwing up a bracket or letter somewhere in the original file...

    Also did NOT know about it already testing for True.

    Thanks, Chapel!
  • Are you able to post the project? If so, I can take a look at if for you—though, please mention where I should look.

    Regardless. It's likely going to be one of a few things:
    1. You're missing one or more angle brackets around one or more tags—either macro tags or HTML tags, since your examples show you're using them.
    2. You're missing one or more entire closing tags for a container/non-void macro or HTML markup.
    3. You've interleaved the opening and closing tags of two or more container/non-void macros and/or HTML markup. For example:
      <<if …>>
      <span>
      <</if>>
      </span>
      

    PS: You didn't manually edit the HTML archive by any chance, did you?
  • I believe this is a good time for a good, solid *HEADDESK*.

    A: Exile, you are entirely correct: I was short a bracket.

    2: I had an <</if>> that had somehow (i blame the programmer, who is myself and feeling stupid) got put in the wrong spot, so there was an interleave.

    YELLOW: The portable drive I'm working off has a different version of Sugarcube than my tower at home.

    Thanks guys, and sorry to be a pain over my own dumb mistakes. XD
  • Don't beat yourself up too much. Everyone occasionally needs another pair of eyeballs on a problem—whether that's literally or figuratively. :)
Sign In or Register to comment.