+1 vote
by (170 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

+2 votes
by (159k 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.

by (170 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?

by (370 points)

I know it's been a while since you asked this, but I think I have a solution.

In order to make sure you don't hit any repeat cards, in each individual card's passage, you can add that card to a separate array that holds the ones you've already gone through. So, it would look like this:

<!--this is the code you'd add to your starting passage--!>

(set: $finished to (a:))

<!--this is the code you'd put at the bottom of your "1" card, and then each subsequent cards, substituting the "1" for whichever card you're on--!>
{
(set: $finished to $finished + (a: "1"))(set: $read to $read - $finished)

(if: $read's length > 0)[(link: "Next Card")[(goto: 1st of $read)]]
(else:)[(set: $read to (shuffled: ...$finished))
(set: $finished to $finished - $finished)
(link: "Start Over")[(goto: 1st of $read)]]}

I tested this with 3 variables, and it recycled them each time in random orders, and you never got the same ones twice unless it happened to be the last of a cycle and then the first of the next.

I hope this helps!

...