> 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，并将起始章节名称更改为 `Welcome`.<br>
2. 在 Welcome 章节的 Objective 字段中添加以下内容：\
   `The time of day currently is {TimeOfDay}. Welcome the player and ask him how his {TimeOfDay} is going.`\
   \
   请注意，在花括号之间添加任意字符串后，它就会成为一个变量。我们在这里将时段设为变量，然后可以从 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', 'Replace it with time');
  narrativeKeys.set('chapter1', 'The journey begins in a small village.');
  // 根据需要添加更多叙事键
  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.
