Howdy, Stranger!

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

Help with multiple if's

I can't seem to get more than 2 ifs working in a statement. I want to re-use passages a lot so I need more complex if checks.

If I'm using a single passage where different events occur at different hours of the day or within a window of a number of hours and a default display if no events are occurring.

If I have a morning event to be triggered before 9:00 and an afternoon event from 15:00, I can just put something like -
<<if $day is 1 and $time is lt 10>>display am<<elseif if $day is 1 and $time is gte 15>>display pm<<else>>display generic<<endif>>

...and that works fine but if I then want a specific window such as between 15:00 and 20:00, I can't work out how to do it.
I've tried various possibilities, including:
<<elseif if $day is 1 and $time gte 15 and lte 20>>display pm

and
<<elseif if $day is 1 and $time gte 15 and $time lte 20>>display pm

but neither seem to work. Please tell me what I'm doing wrong and what is the best way to ask multiple if's?

Comments

  • You need to state which Story Format (and version if known) you are using when you ask a question, as answers can be different for each one. I will assume you are using Sugarcane.

    There are a couple of syntax errors in your examples:

    1. If you are using operates like lt and gte you don't use the is operator.

    2. There is no extra if keyword in an <<elseif>> macro.

    Try the following:
    <<if $day is 1 and $time lt 15>>display am<<elseif $day is 1 and $time gte 15>>display pm<<else>>display generic<<endif>>
    


    3. When checking if a variable's value is between two values, you need to include the variable's name in both sub-expressions.
    <<elseif $day is 1 and $time gte 15 and $time lte 20>>display pm
    
  • Thank you, your last statement was especially useful but I thought I'd tried that already. In any case I know now to repeat the variables name.

    So sorry for not specifying my story format. It is Sugarcane. I thought putting that as a tag would be enough. I'll make sure to do both from now on.

    I'll return with results. Thanks!
  • Thank you so much, that seems to be working now. :)
  • ffs wrote: »
    I thought putting that as a tag would be enough.
    It used to be enough to put the story format name as a tag but your original post does not have any tags, they would appear near the bottom of your post near the 'Quote' link.

    Now because there are more story formats (like SugarCube and Harlowe) and because people are using different versions of a particular story format, and each version can have different features it has become more complex.

    I would suggest using a story format name based tag (eg. harlowe1, sugarcube2, jonah, ,,,) to help with searching via tags, as well as including the story format name and version number somewhere within your original post.
  • OK, thank you I will.
Sign In or Register to comment.