Adding cycling area descriptions for flavour

Twine Version:
Story Format: Harlowe 3.3.3

Essentially, I want to do something similar to the short bursts of atmosphere in Anchorhead, and I’m not sure how to go about it. I know you can use cycling links in Twine, but is there a way to have cycling text each time the player comes back to a certain passage?


The kitchen is messy.
I can hear the microwave beeping.

and on return:

The kitchen is messy.
There’s powdered sugar paw-prints dotted across the floor.

As an additional question: is there a way to make it display nothing, as well? Constant flavour gets old, so it’d be nice to have a way to have a 50-50 chance whether or not the additional text gets added.

(The best thing I could come up with my limited knowledge is adding some sort of (if: visits is ___ ) macro, but I’m not sure how I’d make that recurring without adding in all the potential situations manually - (if: visits is even) and its counterpart don’t really get me what I want, cause I want to cycle through more than two lines of text.)

Do I understand correctly when I think that you don’t want the responses to be generated at random, but for there to be a specific sequence of responses? If so, maybe something like:

(set: $variablename +=1)
(if: $variablename is 1)[The kitchen is messy. I can hear the microwave beeping.]
(if: $variablename is 2)[The kitchen is messy. There are pawprints on the floor.]
(if: $variablename is 4)[The kitchen is messy. There is cheese in the fridge.]

So each time you enter, the variable goes up by one, and a specific response is given; in this case, when you enter for the third time, there is no response.

I think you’re going to have to write the code for it however you want it to work.

Using visits is definitely the way, I think.

If your options are short and you just want a simple cycle you could use (nth:) (for a simple sequence of descriptions), possibly wrapped in an if statement so it doesn’t happen all the time. Something like this (untested):

(if: (random: 1,100) <= 50,
    (nth: visits, "I can hear the microwave beeping.",
        "Powdered-sugar paw-prints dot the floor.")))

For fancier conditions you could (as you said) use a chain of (if:)[...](else-if:)[...] statements, or if the texts are all short you could use (cond:) (which is similar to a chain of if statements but with less punctuation). In this case you’d have to make the visits number loop around by yourself: maybe something like 1 + (visits % 13) if you had 13 options (would give you a number between 1 and 13).

So (also untested):

(set _v to 1 + (visits % 7))
    _v is even, "",
    _v is 1, "I can hear the microwave beeping.",
    _v is 7, "Powdered-sugar paw-prints dot the floor.")

Hope that gives you at least a starting point…

Alternatively, you could use (either:). It has a bit more randomness than (nth:), because it chooses a string based on a random number seed, rather than cycling through the statements in order. I haven’t tested it with empty strings, but it’s worth a shot if you’re looking to only have the text sometimes.

Thanks all! The (nth:) and (either:) macros were exactly what I was looking for - using them interchangeably is I think the key to creating the atmosphere I was going for, thanks so much!

1 Like