I've been toying with Twine for a little bit on my own now and I'm sketching out a story with two counters. One is a time counter, X number of days, and that one I think I've got worked out. The other is an energy counter, a number of actions that the reader can take before they have to fall asleep for the day.
The counting up should be the easy part. Declare the variable on the Start passage silently.
[quote]set $days_spent = 0
Declaring the energy counter should also be easy.
[quote]set $energy = 10
Calling up the sleep text should also be easy.
[quote]<<if $energy = 0>>You curl up and fall asleep.<<endif>>
What's vexing me is how to get the $energy variable to count down. Say the reader is presented with the choice of forcing a stuck door open or walking away. Walking away would not take any energy. Trying to force the door open would consume one energy. Or, if I wanted to get really tricky, having it take two or three energy before revealing what's behind it.
Thoughts?
Comments
I'd suggest using
StoryInit
(which is automatically silent) for your initialization, notStart
.That's incorrect. You're doing an assignment there. A single equal sign (
=
) is always the assignment operator, you want one of the JavaScript equality (==
) or strict-equality/identity (===
) operators or the Twine equality (eq
) or strict-equality/identity (is
) operators. I recommend the one of the two strict-equality operators===
oris
. For example:That's fairly easy by using the setter component of wiki links, for example: In that example, I also showed what might be done if the room had a key that could be used. Both it and breaking down the door go the "
Enter room
" passage, but only forcing the door consumes a point of energy.