Twine Version: 2.36.1
Hello I am having issues creating a widget that easily updates a variable and an image (on the sidebar). So far, here is the widget I have:
<<widget energy>><<nobr>>
<<set $energy += $args[0]>>
<<if $energy gte 50>>
<<replace "#energy">><img src="image.png"><</replace>>
<<else>>
<<replace "#energy">><img src="image.png"><</replace>>
<</if>>
<</nobr>><</widget>>
It’s working, and I like being able to use the widget to easily add to the variable(+ updating the sidebar image) by doing <<energy +10>> or -10, etc., but I’m not sure how to implement having a $maxEnergy variable into the code, to cap the energy variable between 0 and 100. I’m sure the solution is simple but I’m very new!
Here is a different bit of code that I’m also using, but I’m not sure if it would work in the widget.
<<set $energy to Math.clamp($energy + 10, 0, $maxEnergy)>>
Thank you in advance.