Howdy, Stranger!

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

Range of Variables for If Statements (Harlowe 2.0)

I'm looking to add a meter, like a build-up of energy, and I'm struggling to find how to write out the if statement to compared a range of values.

To give an idea of what I mean, I want to display certain text when the variable number of $energy is between either 0-25, 26-50, 51-75, 75-99, or just plan over 100.

I've tried to use it simply by using (if:$energy is >=0) and so on, but it doesn't seem to work poperly, and any values over 25 still next the text for when it's over 0.

Any ideas how to do this? Harlowe 2.0, by the by.

Comments

  • edited April 2017
    Try something like this:
    (if: $energy > 99)[...]
    (else-if: $energy > 75)[...]
    (else-if: $energy > 50)[...]
    (else-if: $energy > 25)[...]
    (else)[...] <!-- this will catch 0-24 -->
    

    You need to order your conditions in such a way that only one of them will ever be true, so starting from the bottom and going up like:
    (if: $energy >= 0)[...]
    (else-if: $energy > 25)[...]
    <!-- etc -->
    

    will generally only trip the first condition, since the subsequent conditions also satisfy the >= 0 condition.
  • I can't help you entirely but I had wondered this once myself in sugar cube from which I stumbled upon this formula
    <<if ($energy < 50 && $energy >= 26)>>
    
    The format is definitely not the same but with some ingenuity, I don't doubt there is a way around it.
  • Kkcajj wrote: »
    I can't help you entirely but I had wondered this once myself in sugar cube from which I stumbled upon this formula
    <<if ($energy < 50 && $energy >= 26)>>
    
    The format is definitely not the same but with some ingenuity, I don't doubt there is a way around it.

    You definitely can use a compound statement like that, but if you order your conditions right, you shouldn't really need it in this case (i.e. when there's one variable and the range is linear). The trick here is just to make sure only one condition is being met at a time and that earlier conditions (like >= 0) aren't tripping in place of later conditions.
Sign In or Register to comment.