文档
作出选择

作出选择

你可以使用 Menu 元素创建一个带有选择的菜单。

const narrator = new Character(null);
 
/**
 * 我该怎么办?
 * - 向左走
 *    ~> *你向左走了。*
 *    ~> 跳转到场景 "scene_went_left"
 * 
 * - 向右走
 *    ~> *你向右走了。*
 *    ~> 跳转到场景 "scene_went_right"
 */
 
scene.action([
    new Menu("我该怎么办?")
 
        .choose("向左走", [
            narrator.say("你向左走了。"),
            /* ... */
            scene.jump(scene_went_left),
        ])
 
        .choose("向右走", [
            narrator.say("你向右走了。"),
            /* ... */
            scene.jump(scene_went_right),
        ]);
]);

你可以使用自定义的 Sentence 来显示菜单提示。

// 使用自定义句子显示菜单提示
new Menu(
    new Sentence("我该怎么办?", {italic: true})  // "我该怎么办?" 使用斜体样式
).choose(
    new Sentence([
        "向", Word.bold("左"), "走" // "向左走" 中的 "左" 使用粗体样式
    ]
), [
    /* ... */
])