(Harlowe) How to set random passages to one link?

0 votes
asked Dec 6, 2017 by LizzieFlynn200 (160 points)
I'm using Harlowe 2.0.1 to make a simple game about Malala for a Social Studies project, and I want to make a link that shuffles through six variables to send the player to one of six different passages. Is this possible, or do I need to simplify/change my idea?

Thank-you in advance.

1 Answer

+1 vote
answered Dec 6, 2017 by greyelf (90,650 points)

You could use the (array:) macro to create a collection of Passage names, then use the (shuffled:) macro to randomly sort those names, and finally a (link-goto:) macro to create the link using the 1st element in the shuffled array as the name of the Target Passage.

(set: _list to (array: "Passage 1", "Passage 2", "Passage 3", "Passage 4", "Passage 5", "Passage 6"))

(link-goto: "Next", (shuffled: ..._list)'s 1st)

... obviously your Passage names would be more meaningful than the ones in the above example.

note: You don't state what type of value is stored within your "six variables" but if you really need to use there value as the determining factor and if those six variables contain the Passage names then you could build the Array of Names using them like so.

(set: $passageA to "Passage 1")
(set: $passageB to "Passage 2")
(set: $passageC to "Passage 3")
(set: $passageD to "Passage 4")
(set: $passageE to "Passage 5")
(set: $passageF to "Passage 6")

(set: _list to (array: $passageA, $passageB, $passageC, $passageD, $passageE, $passageF))

... and then use the same (link-goto:) macro as the first example.

commented Mar 5 by LizzieFlynn200 (160 points)

It worked great, thanks! I'm actually trying to do a similar thing in another project, but now I need it to remove the first passage from the shuffled list every time I go to the next passage.

I'm making a set of flashcards that I'll be able to use for the rest of the year, and I so far have this code:

(set: $cards to (a: "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"))
(set: $read to (shuffled: ...$cards))

(link: "card.")[(goto: 1st of $read)]

But I need it to send me through the list until I go through all of the cards without repeating any of them. What do I need to add to this code?

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.