Howdy, Stranger!

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

Easy (though apparently not for me) Font question

edited July 2015 in Help! with 2.0
In this (SugarCube 2/Twine 2 Browser version) code block
<<if $playerHealth lt 3>>
You: <span class="health">$playerHealth</span>
Him: $enemyHealth

<<elseif $enemyHealth lt 3>>
You: $playerHealth
Him: <span class="health">$enemyHealth</span>

<<elseif $enemyHealth and $playerHealth lt 3>>
You: <span class="health">$playerHealth</span>
Him: <span class="health">$enemyHealth</span>

<<else>>
You: $playerHealth
Him: $enemyHealth
<<endif>>

my plan was to make one or both players show their health stat to be in the red (literally, with the color red)... but for some reason I can only get one person to be red at a time.

I am sure it's an easy thing that I have missed... but I just don't see it.

Any help would be appreciated.

Sage.

Comments

  • You have four problems.

    0. This has nothing to do with fonts.

    1. You're putting looser cases ahead of the more restrictive ones. In general, you want to order your cases from most restrictive (hardest to match) to least restrictive (easiest to match).
    2. This $enemyHealth and $playerHealth lt 3 should be $enemyHealth lt 3 and $playerHealth lt 3.

    For example:
    <<if $enemyHealth lt 3 and $playerHealth lt 3>>
    You: <span class="health">$playerHealth</span>
    Him: <span class="health">$enemyHealth</span>
    
    <<elseif $playerHealth lt 3>>
    You: <span class="health">$playerHealth</span>
    Him: $enemyHealth
    
    <<elseif $enemyHealth lt 3>>
    You: $playerHealth
    Him: <span class="health">$enemyHealth</span>
    
    <<else>>
    You: $playerHealth
    Him: $enemyHealth
    <</if>>
    

    3. You're over complicating things. This accomplishes the same thing with less:
    You: <<if $playerHealth lt 3>><span class="health">$playerHealth</span><<else>>$playerHealth<</if>>
    Him: <<if $enemyHealth lt 3>><span class="health">$enemyHealth</span><<else>>$enemyHealth<</if>>
    
    Or:
    @.health;$playerHealth@@.health;$enemyHealth@@<;<else>>$enemyHealth<</if>>
    
  • edited July 2015
    (do you really always start your lists with zero even in their NON-programming uses? ha-ha, hilarious)

    0. I originally had CSS in there instead of Font, but I knew that wasn't right. Makes sense that it's not really about font-color now, when I look at your answers, but going into it I thought it was a CSS issue. I can see that was never the problem to begin with. It only appeared that way to me.

    1. I didn't know about the more-restrictive -> less-restrictive thing. Good tip. Thank you.

    2. Ah... of course... check both sides for their results separately when using the AND. Got it.

    3. Oh!!! Right. Put them all in one line... clever. This makes much more sense to me now.

    And finally
    @ all about?

    EDIT: Okay.. so those look like a start and end class abbreviation. Can they be used for anything else?

    Thank you times a billion.
  • Sage wrote: »
    (do you really always start your lists with zero even in their NON-programming uses? ha-ha, hilarious)
    No. I used zero there since it was the "You used the wrong {title, category, tags}" problem and thus not really related to your actual issues (1–3). I could have left it unnumbered, but numbering it allowed me to start off by saying you had four problems. ;}

    Sage wrote: »
    1. I didn't know about the more-restrictive -> less-restrictive thing. Good tip. Thank you.
    Well, think about it. In a situation like this, where the cases of one <<if>> chain test the same $variables, if the easier to satisfy cases come before the harder to satisfy ones, then they'll always (probably) satisfy their tests before the harder to satisfy ones and end the <</if>>.

    For example, let's do something similar to your original code, but change the $variables to booleans to keep things simple:
    <<if $playerHealthLow>>
    	/* Case 1: Satisfied if $playerHealthLow is true. */
    <<elseif $enemyHealthLow>>
    	/* Case 2: Satisfied if $enemyHealthLow is true. */
    <<elseif $playerHealthLow and $enemyHealthLow>>
    	/* Case 3: Satisfied if both $playerHealthLow and $enemyHealthLow are true. */
    <<else>>
    	/* Case 4: Satisfied. */
    <</if>>
    
    Do you see how if the third case is able to be satisfied, then both of the first two cases will be satisfied as well? And that means that the third case will never even be tested, because a previous case was satisfied, thus stopping the chain.

    Sage wrote: »
    @ all about?
    That's the custom styles markup. See: SugarCube 2.x docs > Markup.
  • Solid as always. Thank you.
Sign In or Register to comment.