Twine Version: Sugarcube 2.0
[also choose a Story Format tag above]
Help needed -
I have been trying to create a system where repeating action will change multiple variable. For example if the player went to the gym and worked out then his strength goes +1 and energy - 10.
And if he does it again the effect increases the stat.
I have already set the variables of the player with strength set to 0 and energy one to 100. What kind of code should I use.
current Energy: $energy
current Strength: $strength
\<<if $energy >= 10>>
<<link "Workout" PassageName>> <<set $energy to $energy - 10, $strength =$strength + 1>> <</link>>
This is how I would do it if you want to implement it simply, but if you don’t like that the passage is reloaded every time you click workout, I would recommend then moving it into its own Widget
in a extra widget I would do something like this:
::widgets (Tagged with "widget" important! ) (I also add "nobr" tag to my widget so it wont put in <br> into my text)
<<if $energy >= 10>>
<<set $energy to $energy - 10, $strength =$strength + 1>>
That was a nice workout!
I am too tired to Workout Right now...
That’s because the story caption element is only updated when you navigate to a new passage. It doesn’t monitor changes to the variables and update itself automatically. To update it without navigating to a new passage, you need to use the <<replace>> macro. Here’s a widget that does that:
So you won’t need to go to a new passage and you will only replace the stats you are currently changing instead of the whole StoryCaption, (but this is just my personal preference as I do put a lot of new elements into my StoryCaptions)