Is it possible to have an (either:) list or something similar that has more options after more variables are changed?

Twine Version: 2.6.2
Harlowe Version: 3.3.5

I’m trying to make a story about a card game with a passage that you would go back to constantly, which would be playing the game. At the beginning of the passage, I plan to have it so it tells you the deck, though you only start with 10 cards unlocked the first time you play. I’m wondering if it’s possible to make it so that when you unlock a card, it’s added to the list of available cards at the beginning of each game.

What you want here is an array (or possibly a dataset if it’s not possible to have duplicate cards). You can add cards to the array as they’re unlocked, and (either: $myArray) (replace the variable with whatever your array’s actual name is) will give you a random value out of the array.

2 Likes

Just a small correcting…

As mentioned in the (either:) macro’s documentation…

As with many macros, you can use the spread ... operator to place all of the values in an array or dataset into (either:), and pick them randomly. (either: ...$array) , for instance, will choose one possibility from all of the array contents.

…the spread ... operator should be used when passing an Array as an argument to that macro.

The following as slightly more detailed example, that includes the usage of the spread ... operator…

1: Define the initial contents of the Deck…

(set: $deck to (a: "ace-of-spaces", "five-of-clubs", "eight-of-diamonds", "three-of-spades"))

2: Randomly select a card from the Deck…

(set: $selected to (either: ...$deck))

3: At some later point add an additional card to the Deck, using Array arithmetic…

(set: $deck to it + (a: "ten-of-hearts"))

note: If multiple cards will be randomly selected from the Deck over time, and you also want the selected cards to be removed from the Deck so they can’t be randomly selected again, then you might want to shuffle the Deck upfront, and then use the (move:) macro to repeatable select the current top card from it.

1: Create a “shuffled” Deck of cards, using the (shuffled:) macro…

(set: $deck to (a: "ace-of-spaces", "five-of-clubs", "eight-of-diamonds", "three-of-spades"))
(set: $deck to (shuffled: ...$deck))

note: Technically all of the above could be done within a single (set:) macro call, but I used two calls to make sure the sequences of events are clear.

2: Take the top card from the shuffled Deck…

(move: $deck's 1st into $selected)

note: You will receive an error if you try to move an item from an empty Array, so you might want to check the current value of the $deck's length property before executing the above.

3: At some later point add an additional card to the Deck, using Array arithmetic…

(set: $deck to it + (a: "ten-of-hearts"))
(set: $deck to (shuffled: ...$deck))

note: I only re-shuffle the Deck after adding an additional card to it so that all the newly added cards don’t gather at the bottom of the Deck. If you don’t mind those new cards being placed there then remove the above (shuffled:) macro call.

4 Likes

Thanks for the correction! I’m mostly a Sugarcube user and there it’s just either($myArray); I had forgotten Harlowe had an added wrinkle there.

2 Likes

No problem, I understand that it can be difficult to keep all the differences of the Story Formats in mind, especially when there are four main ones and a number of less common ones as well… :slight_smile:

(I cheat, and always reference the relevant documentation! lol)

3 Likes