*if command text

Is there a way to change text with the *if command? I’m trying to implement a sanity mechanic and have the stat screen change depending on the sanity level.

My code looks like this

*if Sanity > 60
  You
*elseif Sanity < 60
  Me

Edit: The error message I’m getting is that I have to have *goto or *finish

If you see it like this it should work

*if Sanity > 60
  You
*else
  Me

or you could do

*if Sanity >= 60
    You
*else
    Me

just to make sure everything is covered

Im still getting an error, does that work for multiple like

*if Sanity > 60
  Power
*elseif Sanity > 30
  My Power
*else
  Your power

This should work(just replace the goto with whatever youre using/choose to use to continue the story)

*if Sanity > 60
    Power
    *goto next_part
*elseif Sanity > 30
    My Power
    *goto next_part
*else
    Your power
    *goto next_part
2 Likes

If you don’t want to use *goto or *finish

*if Sanity > 60
  You
*if Sanity <= 60
  Me

For multiples:

*if Sanity > 60
  Power
*if ((Sanity > 30) and (sanity<=60))
  My Power
*if Sanity <= 30
  Your power
1 Like

For your original example, you could also use multireplace: @{(Sanity > 60) You|Me}

But that won’t work if you want to test more than two levels of the Sanity stat. For that, *if/elseif/else is still best, and the key thing to remember there is that you need a *goto at the end of each indented bit. (Unless you turn on Implicit Control Flow, which removes the need for *gotos.)

Edit: And it’s worth noting that while @ChanceOfFire’s solution totally works (and I’ve used it myself at times) it’s very bug-vulnerable. It’s not hard to get a >= or <= wrong and end up with something that doesn’t work for various stat values. For example,

*if Sanity > 60
  You
*if Sanity < 60
  Me

will display nothing for players whose Sanity is 60, and

*if Sanity > 60
  You
*if Sanity >= 60
  Me

will display nothing for players whose Sanity is under 60. Both of those are relatively easy mistakes to make.

If you really don’t want to use *gotos in your *if/elseif/else blocks – if copying *goto next and hitting Ctrl-V a couple times just shatters your flow – then I’d suggest turning on ICF, rather than getting into the habit of hard-coding a bunch of *if criteria without using *elseif or *else.

2 Likes

Also it shows both “You” and “Me” if Sanity is more than 60, which is another thing you generally want to avoid. (And I read that wrong first! See how easy it is to mess that up?)

1 Like

This topic was automatically closed 24 hours after the last reply. If you want to reopen your WiP, contact the moderators.