> 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).

# 叙事设计键

本指南展示了如何动态向叙事设计部分和触发器传递变量

我们将创建一个简单的场景，其中角色会欢迎玩家，并根据玩家所在的时间段询问他们晚上或早上的情况。

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

   <figure><img src="https://2402152281-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2FjIXZMLIToi7k1RfftC3n%2Fimage.png?alt=media&amp;token=df966094-b478-4f71-b108-c83438ca9ac2" alt=""><figcaption><p>叙事设计键</p></figcaption></figure>
3. 在 JavaScript 中设置叙事模板键

   要使用自定义模板键初始化你的叙事设计框架，你可以传入 `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: 'your-character-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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
