Heey again,
I feel like I'm a regular in this forum now...
Anyway, I'm wondering if it's possible to establish a maximum value to a variable.
I'm using Twine 2 and Sugarcube 2.18.
My idea is to create a variable to describe a relationship status between two characters. I was thinking of something from 0 to 10, where 0 was the worse the relationship could be at, and 10 the best. And I was thinking throughout the story, depending on the choices made, to simply use something like <<set $relationship ++ >>. But I didn't want the value to ever surpass the 10. How do I do that without having to always go check if the variable is at 10 yet??
I don't know if I was really clear, but I'd appreciate any help
Comments
Some more advanced methods.
1. Make a widget (goes in a widget-tagged passage).
Usage:
2. Use the ? operator, only works really well with adding 1 point at a time.
3. Use a special passage like PassageFooter or PassageDone, etc. YMMV, as the variable will be over 10 for some of the passage's code.
There's a few other ways too, like the <number>.clamp() method and the Math.clamp() method, but I think one of these is probably easiest to implement.
You can add tags to passages in the editor. Adding the tag 'widget' will register the passage as widget definitions. Widgets are like macros, but are defined in TwineScript (instead of JavaScript). To add a tag, click on the +Tag option, type in the tag, and click Add. I posted images for reference.