Giving stats a name as well as a value

Twine Version: 2.3.16
Story Format: 2.36.1

I want some, not all, of my stats to show up in the sidebar as a description of what they reflect, possibly with the numerical value as well.

For example, strength.
And while I have this code in StoryCaption:

Strength: <<print $Strength>> <<if $Strength == 0>>(Puny)<<elseif $Strength == 50>>(Average Strength)<<elseif $Strength == 100>>(Mighty)<</if>>

And this in StoryInit:

<<set $Strength to 80>>

which does show the value, but it only does so while that number is current. I would like to be able to set the variable so that from between 0 and 10 = (puny), between 11 and 20 = (weak), etc.

I have seen codes with gte and lte, but I’m not 100% on implementing it.

I think you want to code it like this so that there are ranges

Strength: <<print $Strength>> <<if $Strength gte 0 and $Strength lt 50>>(Puny)<<elseif $Strength gte 50 and $Strength lt 100>>(Average Strength)<<elseif $Strength gte 100>>(Mighty)<</if>>

An explanation. There are two parts here:

First, the and operator. Note that even if you are checking the same variable twice you want to write

<<if $Strength gte 0 and $Strength lt 50>>

instead of

<<if $Strength gte 0 and lt 50>>

Second, we have various operators: gte, lte, gt, lt, and eq. The abbreviations should be obvious but if they are not, check out this list

To make operations like this work you will need to use exclusive and inclusive operators in an alternating fashion. In the code we use greater than or equal to (gte) and less than (lt) in each statement.

If we used only inclusive operators (gte and lte) with the above values, different comparisons would overlap…for example, 50 would be counted in two if statements. However, you could achieve the same effect with inclusive values just by changing the numbers to not overlap:

that is,

gte 0 and lt 50
gte 50 and lt 100

is the same as

gte 0 and lte 49
gte 50 and lte 99

so long as you always use whole numbers. If you start dividing or using decimals it is best to stick with the first style (alternating).

1 Like

That works perfectly, and I even understood why! :slight_smile:

1 Like