Help trying to figure out how to do arrays based off random numbers

So I’m trying to do random card draws based off a randomly generated number. it goes something like this. X causes you to draw 1-4 cards from a randomly generated deck. Lets say the deck is 10 cards. Cards themselves can be like the numbers 1-10 for this example.

1 Like

Welcome Gobbytygoo!

Your question is not crystal clear. I don’t know if you intend to put the cards drawn in the packet aside, in order not to draw twice the same card, or if you intend to put the cards drawn back into the deck, thus you could draw the same card more than once.

In any passage you can create a variable you name $deck:
For instance, with only one of the four suits:

(set: $deck to (a: "King of Spades", "Queen of Spades", "Jack of Spades", "Ten of Spades", "Nine of Spades", "Eight of Spades", "Seven of Spades", "Six of Spades", "Five of Spades", "Four of Spades", "Three of Spades", "Two of Spades", "Ace of Spades"))

If you want to draw any card:

You draw a card. It's the (either: ...$deck).

You can iterate the command as many times you like, each time any card can come, even one already drawn. If you want to draw different cards, you can use the (shuffled:) command https://twine2.neocities.org/#macro_shuffled
With this macro you shuffle members of the array, It then allows you to pick any member of the arrow.
For instance you can pick the two ‘top’ cards:

(set: _deck to (shuffled: ...$deck))
You draw two cards at once. Here comes the (print: _deck's 1st) and the (print: _deck's 2nd).
1 Like