Howdy, Stranger!

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

"If" statements incorrectly evaluated

edited May 2015 in Help! with 1.x
I've run into an issue when setting a variable with a cycling link in 1.4/ SugarCube. The cycling link successfully changes the variable, however, the following if statement does not evaluate correctly. Here's the code:
<<cyclinglink "$familyone" "sister" "brother">>

[[Now sing|First Song]]

Then on the "First Song" passage..
<<print "$familyone">>
<<if "$familyone" eq "sister">>
[["sister"]]
<<else>>
[["busted"]]
<<endif>>

Even when $familyone is set to "sister" via the cycling link, I get the output:
sister

busted

As you can see, I tested that the variable was in fact set to "sister," and it correctly printed it as such. However, I still get the "else" output from the if statement. Any insight into fixing this issue would be greatly appreciated!

Comments

  • The problem is that you are wrapping the $familyone variable in your <<print>> and <<if>> macros in double quotes, change your code to the following:
    <<print $familyone>>
    <<if $familyone eq "sister">>
    [["sister"]]
    <<else>>
    [["busted"]]
    <<endif>>
    
  • I'll add a few additional comments:
    • As long as you're using SugarCube version >= 1.0.22, you don't need to use the <<print>> macro to print simple $variables, just put the $variable directly in your normal text. You may continue to use <<print>> if you prefer, but it's not required in this case.
    • There's nothing about the passage names/titles used within the link markup which would require you to quote them there. You may continue to quote them, but it's not required in this case.
    For example:
    $familyone
    <<if $familyone is "sister">>
    [[sister]]
    <<else>>
    [[busted]]
    <</if>>
    
  • greyelf wrote: »
    The problem is that you are wrapping the $familyone variable in your <<print>> and <<if>> macros in double quotes

    Thank you so much! You're absolutely right, I feel so silly now!
Sign In or Register to comment.