> For the complete documentation index, see [llms.txt](https://docs.convai.com/api-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/web-plugins/narrative-design-guide/narrative-design-keys.md).

# Narrative Design 键

我们将创建一个简单场景，角色会欢迎玩家，并根据玩家当前的时间段询问他们晚上或早上过得怎么样。

1. 在 playground 中，为你的角色启用 Narrative Design，并将起始章节名称更改为 `欢迎`.<br>
2. 将以下内容添加到 Welcome 部分的 Objective 字段：\
   `当前时间段是 {TimeOfDay}。欢迎玩家，并询问他这个 {TimeOfDay} 过得怎么样。`\
   \
   请注意，在花括号中添加任意字符串后，它就会成为一个变量；而我们在这里所做的是将时间段作为变量加入，然后在 Unreal 中我们可以传入“Morning”或“Evening”这两个词，角色会据此做出相应回应。<br>

   <figure><img src="/files/36a936e916fb6cec77caae79f603cfd4d7ca3673" alt=""><figcaption><p>Narrative Design 键</p></figcaption></figure>
3. 在 JavaScript 中设置 Narrative Template 键

   要使用自定义模板键初始化你的 narrative design 框架，你可以传入 `narrativeTemplateKeys` 参数，在实例化 `convaiClient`。这使你能够以编程方式定义和构建叙事流程。

```javascript
//示例
function getNarrativeTemplateKeys(): Map<string, string> {
  const narrativeKeys = new Map<string, string>();
  // 用叙事键和值填充映射
  // 这可以来自数据库、配置文件或其他来源
  narrativeKeys.set('TimeOfDay', '将其替换为时间');
  narrativeKeys.set('chapter1', '旅程始于一个小村庄。');
  // 根据需要添加更多叙事键
  return narrativeKeys;
}


const client = new convaiClient({
  apiKey: 'your-api-key',
  characterId: '你的角色ID',
  narrativeTemplateKeys: getNarrativeTemplateKeys()
});
```

<br>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/web-plugins/narrative-design-guide/narrative-design-keys.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
