0 votes
asked by (460 points)
Sorry if this has been asked before and my googlefu wasn't good enough to find an answer.

Say I have a link [game] and I want it to randomly choose from a pool of passages like [colin1], [ryan1], [wayne1], and [hoedown]. If it goes to [colin1], it's taken out of the pool and [colin2] is added in. [hoedown] can be visited repeatedly. Is there a way to do this cleanly in Harlowe?

I also have some secondary questions if that's alright. It'd just be nice to have some opinions on these. Are there things Harlowe and Sugarcube are flat out incapable of, but possible in Snowman? If there are, is it worth switching to Snowman now so I don't get curtailed later in case I want to do something more complex? Lastly, what are the differences between Twine and Yarn? Thanks for any help!

1 Answer

+1 vote
answered by (55.2k points)
selected by
Best answer

Easiest solution is to use an array. Here's some code:

First, in a startup-tagged passage, this:

(set: $psgPool to (a: 'colin1', 'ryan1', 'wayne1', 'hoedown'))

Then, in the passage with the link: 

(link: 'do the thing')[
    (set: _psg to (either: ...$psgPool))
    (set: $psgPool to it - (a: _psg))
    (goto: _psg)

In the passages that are linked to, like 'wayne1':

(set: $psgPool to it + (a: 'wayne2'))\

[[link back to the other passage]]

And in the 'hoedown' passage:

(set: $psgPool to it + (a: 'hoedown'))\

[[link back to the other passage]]

If you don't want one of the passages to add another passage to the list of options, just completely exclude the (set:) at the beginning.

About Formats

There's nothing in Snowman that can't be done in SugarCube.  You should really only use Snowman if you want to build your game completely in JavaScript, without any of the macros and features provided by the other formats, or if you're mostly just using Twine for the IDE. In short, unless you know enough about what you're doing to know you need Snowman (and you very well might), you probably don't need Snowman. 

Harlowe does lock you out of accessing its internal stuff through JavaScript though, and can be frustrating to work with for that reason.  I suggest making a new question for this if you're really that concerned about it.

edit: About Yarn. 

This Yarn is more of a dialog interface system for use in other games, and allows you to import some bare-bones Twine syntax. As far as I know, other than being loosely based on Twine's interface and allowing you to import Twine files (though in a limited fashion), they don't really have all that much in common. That said, there are many other programs called Yarn, including a package manager and an IF platform (which also allows you to import from Twine, but only Twine 1 and in a limited fashion as far as I can tell), so you may need to be more specific. 

commented by (460 points)
Thank you! This is exactly what I needed! I had a feeling arrays were the solution, but I had a hard time wrapping my head around the array page in the wiki. Thanks for answering my other questions too, you've been beyond helpful and informative.
Welcome to Twine Q&A, where you can ask questions and receive answers from other members of the community.

You can also find hints and information on Twine on the official wiki and the old forums archive.

See a spam question? Flag it instead of downvoting. A question flagged enough times will automatically be hidden while moderators review it.