How to randomize where a character is in a passage that links to the continuation of their arch?

If you are requesting technical assistance with Twine, please specify:
Twine Version:2.4
Story Format: Sugar Cube

I would like to have characters that are moving around town randomly but when you meet them you can continue the story arch. What’s the best way to do this?

In your PassageHeader insert this code:
<<set $wanderer_chance to random(0,4)>>

That means that each time the passages changes a random number will will be rolled. (0,4) means there is a one in five chance (0,1,2,3,4) that it will be 0.

Now there are two options:

Option 1. Insert the wanderer text manually into each passage you want the wanderer to possibly show up in.


For example, in a “park” passage insert <<if $wanderer_chance eq 0>> The wanderer is sitting on the bench [[Talk to him]] <<endif>>.

In the pub passage, insert <<if $wanderer_chance eq 0>> The wanderer is drinking an ale [[Talk to him]] <<endif>>

Option 2. Create a one-size-fits-all text block.


In the passages that you want the wanderer to possibly show up in, insert
<<include "wanderer_text">>

Now, create a new passage. Name it wanderer_text and insert something like this:
<<if $wanderer_chance eq 0>> The wanderer appears. [[Talk to him]]<<endif>>

This way you can quickly change the text across all passages that the wanderer appears in.