0 votes
by (120 points)
I'm trying to figure how - if it's possible - to have a set of multiple potential randomized options, but each option that gets used is then not available to be used in the next random selection.

So basically once the player clicks next, they can randomly get any 3 of the following: A, B, C, D, E, F, G,  HOWEVER, for each result they get, the next one can't get a second of an already used result.

Example:

Player finds a treasure box and can get any 3 of the following when they open it: (sword, shield, mana potion, wand, gold, glowing gem)

Player opens the box and gets (Shield), (wand), (gold)

I'd greatly appreciate any help with this.

2 Answers

+1 vote
by (68.6k points)

In future.  You should always mention both the compiler and story format, and their versions (because, yes, it's important).  Generally, you do that via tags (though it doesn't hurt to also mention them in the body of your question).


What you want to do it possible, but how you do so is dependent upon which story format you're using.  Here's one way for each of the three primary story formats.

 

SugarCube (≥ v2.20.0)

You may use the <Array>.pluckMany() method to pull multiple random members from an array.

<<set _pulled to ["A", "B", "C", "D", "E", "F", "G"].pluckMany(3)>>\
1: <<print _pulled[0]>>, 2: <<print _pulled[1]>>, 3: <<print _pulled[2]>>

 

Harlowe

You may use the (shuffled:) macro to randomize a list or array.  From there simply access the first three members.

(set: _pulled to (shuffled: "A", "B", "C", "D", "E", "F", "G"))\
1: (print: _pulled's 1st), 2: (print: _pulled's 2nd), 3: (print: _pulled's 3rd)

 

Snowman

You may use the _.sample() method to pull multiple random members from an array.

<% s.pulled = _.sample(["A", "B", "C", "D", "E", "F", "G"], 3) %>
1: <%= s.pulled[0] %>, 2: <%= s.pulled[1] %>, 3: <%= s.pulled[2] %>

 

–1 vote
by (44.7k points)

Basically, you want to make an array of the options, and then you can use the pluck() function to pull items out of that array.  For example:

<<set _itemArray = ["A", "B", "C", "D", "E", "F", "G"]>>\
<<set $items = [_itemArray.pluck(), _itemArray.pluck(), _itemArray.pluck()]>>\
Player opens the box and gets: $items[0], $items[1], $items[2]

The pluck() function removes the item from the array, so it each item will be unique.

Hope that helps! smiley

...