chooseChoiceIndex method

void chooseChoiceIndex(
  1. int choiceIdx
)
Chooses the Choice from the currentChoices list with the given index. Internally, this sets the current content path to that pointed to by the Choice, ready to continue story evaluation.

Implementation

void chooseChoiceIndex(int choiceIdx) {
  var choices = currentChoices;
  assert(choiceIdx >= 0 && choiceIdx < choices.length, 'choice out of range');

  // Replace callstack with the one from the thread at the choosing point,
  // so that we can jump into the right place in the flow.
  // This is important in case the flow was forked by a new thread, which
  // can create multiple leading edges for the story, each of
  // which has its own context.
  var choiceToChoose = choices[choiceIdx];
  onMakeChoice?.call(choiceToChoose);
  state.callStack.currentThread = choiceToChoose.threadAtGeneration;

  _logger.finest('choiceToChoose : ${choiceToChoose.toJson()}');
  choosePath(choiceToChoose.targetPath!);
}