Deferring .pluck

0 votes
asked Sep 13 by Charlie (3,820 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
answered Sep 13 by greyelf (37,190 points)
selected Sep 13 by Charlie
 
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

.

commented Sep 13 by Charlie (3,820 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.
Welcome to Twine Q&A, where you can ask questions and receive answers from other members of the community.

You can also find hints and information on Twine on the official wiki and the old forums archive.

See a spam question? Flag it instead of downvoting. A question flagged enough times will automatically be hidden while moderators review it.
...