0 votes
by (8.9k points)

I have a character generation screen that plucks a surname from an array in my StoryInit.  The aim was to prevent the surname from recurring later in the game (so that randomly generated NPCs aren't generated with the same surname, for instance).

<<set $pcSurname to setup.surnames.pluck()>>

However, the player can click through several surname options in one session (if he were generating multiple characters).  I've just realised that the game will be plucking surnames as it goes, leading potentially to a greatly diminished (or empty) name list for the remainder of the game.

This is obviously sub-optimal.  Is there a way to have the game pluck the chosen surname on the next passage, i.e. on commit rather than on generation?

1 Answer

+1 vote
by (159k points)
selected by
 
Best answer

You can think of <Array>.pluck() as basically being a <Array>.random() followed by a <Array>.delete() so you can use those two methods yourself to achieve your 'delayed' pluck() functionality

<<set _list to ["one", "two", "three", "four", "five"]>>\
original list: _list

<<set _first to _list.pluck()>>\
first: _first
\
<<set _second to _list.random()>>\
<<run _list.delete(_second)>>\
second: _second

final list: _list

.

by (8.9k points)
Thanks Greyelf, both for the solution and the explanation.  I didn't have a conceptual framework for how pluck() worked in my head before reading your answer.
...