1

First of all I'm quite new to Twine and Sugarcube but I've found my way until now but now I've been struggling to find and answer to the below issue:

I have a character that has several stats like strength and energy.

I use them like this:

In the StoryInit:

<<set $energy to 100>>

In the passages of the story:

<<set $energy to $energy +10>>

Now I want to set a maximum and a minimum for all the stats seperately. I used to do it like this:

<<set $energy to $energy +30>>
<<if $energy gte 100>><<set $energy to 100>>
<</if>>

But to this every time is a lot of work and and just asking for mistakes.

Is there and what is the best way to limit these stats seperately. (so strength has a max of 200 and energy a max of 100)

Linda Paiste
  • 38,446
  • 6
  • 64
  • 102
Dave
  • 11
  • 1

1 Answers1

1

I haven't used Twine for a while but I think you can just use javascript Math stuff as normal:

<<set $energy to Math.clamp($energy + 30, 0, 100)>>

Or make it into a widget:

<<widget setEnergy>>
<<set $energy to Math.clamp($energy + $args[0], 0, 100)>>
<</widget>>

So you can use:

<<setEnergy +30>>

So you can avoid repetition/mistakes as you say. Make a similar one for strength etc. and just change the 100.