Stat States Coding

Twine Version: 2.6.2.0

Hi there, first of all thank you for taking the time to read this, and extra thank you to anyone who tries to help.

So, I am a total newbie to any kind of coding. I’m not sure why this isn’t working as from what I can find in tutorials and in replies to similar questions, it seems like it should be working? Basically, I have my stats on a scale from 1 to 11, with 6 being neutral. I want the stats page to show a different little blurb depending on how many points the stat has. Ironically, I decided to do it this way because I was struggling so much trying to make the meter macro work.

When I put in this, it works fine:

<<if $adaptable is 6>>
You are not particularly “adaptable”, or “adamant”.
<<else>>
You can be somewhat “adaptable”, though it isn’t unheard of for you to be adamant about something.
<</if>>

It does exactly what I need it to, to a limited degree. When the stat is 6, it shows the appropriate message, and then shows the other message when the stat isn’t 6. But when I tried to expand it with more options…

<<if $adaptable is 6>>
You are not particularly “adaptable”, or “adamant”.
<<elseif $adaptable lt 6 and gt 3>>
You can be somewhat ''adaptable'', though it isn’t unheard of for you to be adamant about something.
<<elseif  $adaptable lt 4 and gt 1>>
You have a tendency to be ''adamant'' more often than not, which can sometimes hinder how adaptable you manage to be.
<<elseif $adaptable is 1>>
You are an extremely ''adamant'' person. No one can shake you when you’ve decided to stand your ground. Once you’ve made up your mind, that’s that. You have no time or patience for being adaptable.
<</if>>

When I put this in, the stats page doesn’t show anything at all. Am I using elseif incorrectly? The error message keeps giving me this error message: Error: <>: bad conditional expression in <> clause (#1): expected expression, got ‘>’

Am I supposed to tack something else onto the end of elseif statements or something?

Again, thank you for anyone taking the time to help.

Hmmm… looks like you might have to declare the variable again.

<<elseif $adaptable lt 6 and $adaptable gt 3>>

I don’t do SugarCube, but I just have to see if I’m right. :wink:

Thank you for replying. I tried what you suggested and declared the variable again, as I’ll show below. There’s no longer an error, but there’s no text showing up either, it’s just blank.

<<if $adaptable is 6>>
You are not particularly “adaptable”, or “adamant”.
<<elseif $adaptable lt 6 and $adaptable gt 3>>
You can be somewhat ''adaptable'', though it isn’t unheard of for you to be adamant about something.
<<elseif  $adaptable lt 4 and $adaptable gt 1>>
You have a tendency to be ''adamant'' more often than not, which can sometimes hinder how adaptable you manage to be.
<<elseif $adaptable is 1>>
You are an extremely ''adamant'' person. No one can shake you when you’ve decided to stand your ground. Once you’ve made up your mind, that’s that. You have no time or patience for being adaptable.
<</if>>\

Okay I’m a dummy and I figured out the problem. There was an issue in the coding where I set my variables. Thank you so much for trying to help <3

1 Like

Output $adaptable before your if statement and determine if any of the conditions would actually fire. Like, if $adaptable is greater than 6 or less than 1, it wouldn’t get caught by any of the conditions. Do you know the value?

#macros-macro-if

Also, it might be easier to use gte and lte to keep your code more understandable. (6, 5-4, 3-2, 1)

1 Like

Yay! High-five!

1 Like

In a <<if>><</if>> statement conditions are checked in the order they are written. Thus when you reach the second condition, it means the first condition has already been deemed as false.

It means you don’t need to precise both minimum and maximum in each condition. The less writing, the less errors.

Similarly when you reach the last value it means every other values have already been written, so you may use an <<else>> instead.

<<if $adaptable is 11>>
text
<<elseif $adaptable gt 8>>
text
<<elseif $adaptable gt 6>>
text
<<elseif $adaptable is 6>>
text
<<elseif $adaptable gt 3>>
text
<<elseif $adaptable gt 1>>
text
<<else>>
text
<</if>>
3 Likes

Thank you so much for this tip! This will make things much neater/easier, I was worried leaving something out would break the whole thing :sweat_smile:

1 Like