Documentation
Types
SentencePrompt

SentencePrompt

export type DynamicWord = (ctx: ScriptCtx) => DynamicWordResult;
export type DynamicWordResult = string | Word | Pausing | (string | Word | Pausing)[];
export type StaticWord<T extends string | DynamicWord | Pausing = string | DynamicWord | Pausing> = string | Pausing | Word<T>;
export type SingleWord = StaticWord | DynamicWord;
export type SentencePrompt = SingleWord[] | SingleWord;

Examples

  1. Simple string sentence
// "Hello, world!"
const sentence: SentencePrompt = "Hello, world!";
  1. Mixed string sentence
// "Hello, world!" with "world" in red color
const sentence: SentencePrompt = [
    "Hello, ",
    new Word("world", {color: "#f00"}), // a red word
    "!"
];
  1. Pausing sentence
// "Hello, ", pause for 1 second, "world" and wait until player click, "!"
const sentence: SentencePrompt = [
    "Hello, ",
    Pause.wait(1000), // pause for 1 second
    "world",
    Pause, // wait until player click
    "!"
];
  1. Dynamic sentence
// "Hello, you have 100 coins!"
const sentence: SentencePrompt = [
    "Hello, ",
    ({storable}) => {
        return `you have ${storable.getNamespace("game").get("coin")} coins`
    },
    "!"
];
  1. Dynamic evaluated sentence
// "Hello, you have 100 coins!" with "100" in red color
const sentence: SentencePrompt = [
    "Hello, ",
    ({storable}) => {
        return [
            "you have ",
            new Word(`${storable.getNamespace("game").get("coin")}`, {color: "#f00"}),
            " coins"
        ]
    },
    "!"
];