I have used the search function so pardon me if the question has been asked but I have several variables that increase or decrease (numerical, like an rpg) but I want to prevent them from going above or below a certain number. Is this possible? If so, how?
Comments
Anyway, limiting a value to a specific range is known as clamping. The simple answer would be to check the value afterwards and, if it exceeds your specified range in a particular direction, reset it to the min/max.
For example, let's assume a range of [2, 10].
The following works in all Twine 1 story formats and SugarCube:
Clamping after modification, using <<if>> and <<set>>: However, you could also clamp during modification, using Math.min() and Math.max():
Beyond that, SugarCube has a few clamping methods available:
Clamping after modification: Or, again, you could also clamp during modification: