Skip to content

Condition

Condition, based on the result of the function

Parameters

NameTypeOptionalDescription
condition(state: State) => TThe function that defines the narrative branch
variantsRecord<T, ValidAction[]>Narrative Branches

Usage

ts
engine.script({
  start: [
    engine.action.condition(
      (state) => {
        return state.age >= 18 ? "yes" : "no";
      },
      {
        yes: [action.dialog(undefined, "Let me show you an unicorn!")],
        no: [action.dialog(undefined, "You're too young kid")],
      }
    ),
  ],
});

Released under the ISC License.