# Vars

**Vars** 对象表示用户和脚本定义变量的集合。存在许多不同的变量集，它们具有不同的作用域。一些集合支持持久性变量，这些变量会在不同会话之间保存和重新加载。

| 作用域  | 访问方式                                                                                                                                                                  | **支持持久性** | 描述                                                                                                         |
| ---- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------- | ---------------------------------------------------------------------------------------------------------- |
| 全局   | [**DOpus**](https://chaoses-ib.gitbook.io/directory-opus/guan-fang-shou-ce/readme.zh-10/readme.zh-3/readme.zh/dopus.zh)**.vars**                                      | 是         | 可在整个 Opus 中使用的变量。任何函数或脚本都可以访问它们。                                                                           |
| 文件窗口 | [**Lister**](https://chaoses-ib.gitbook.io/directory-opus/guan-fang-shou-ce/readme.zh-10/readme.zh-3/readme.zh/lister.zh)**.vars**                                    | 是         | 特定于文件窗口的变量。持久性变量会根据文件窗口基础在文件窗口布局中保存。                                                                       |
| 标签页  | [**Tab**](https://chaoses-ib.gitbook.io/directory-opus/guan-fang-shou-ce/readme.zh-10/readme.zh-3/readme.zh/tab.zh)**.vars**                                          | 是         | 特定于特定标签页的变量。持久性变量会根据标签页基础在文件窗口布局中保存。                                                                       |
| 脚本   | <p><a href="script.zh"><strong>Script</strong></a><strong>.vars</strong><br><a href="scriptinitdata.zh"><strong>ScriptInitData</strong></a><strong>.vars</strong></p> | 是         | 特定于特定脚本加载项的变量。                                                                                             |
| 对话框  | [**Dialog**](https://chaoses-ib.gitbook.io/directory-opus/guan-fang-shou-ce/readme.zh-10/readme.zh-3/readme.zh/dialog.zh)**.Vars**                                    | 是         | 特定于特定 [脚本对话框](https://chaoses-ib.gitbook.io/directory-opus/guan-fang-shou-ce/readme.zh-8/readme.zh-4) 的变量。 |
| 命令   | [**Command**](https://chaoses-ib.gitbook.io/directory-opus/guan-fang-shou-ce/readme.zh-10/readme.zh-3/readme.zh/command.zh)**.vars**                                  | 否         | 特定于特定函数的变量。它们不会从一个函数调用保存到另一个函数调用，也不支持持久性。                                                                  |

| 属性名称    | 返回类型                                                                                                                     | 描述                                                                                                                                                                                      |
| ------- | ------------------------------------------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *<默认值>* | *集合:*[**Var**](https://chaoses-ib.gitbook.io/directory-opus/guan-fang-shou-ce/readme.zh-10/readme.zh-3/readme.zh/var.zh) | 返回集合中的变量集合。您可以枚举 [**Var**](https://chaoses-ib.gitbook.io/directory-opus/guan-fang-shou-ce/readme.zh-10/readme.zh-3/readme.zh/var.zh) 元素，也可以通过其索引或名称引用特定元素。关于如何执行此操作的示例在下面的 **Set** 文档中。 |

| 方法名称 | **参数**                    | 返回类型  | 描述                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| ---- | ------------------------- | ----- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| 删除   | <字符串:名称>                  | *无*   | 从集合中删除指定名称的变量。您还可以指定 [通配符模式](https://chaoses-ib.gitbook.io/directory-opus/guan-fang-shou-ce/readme.zh-10/readme.zh/pattern_matching_syntax.zh) 来删除多个变量（或 \* 表示所有）。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| 存在   | <字符串:名称>                  | *布尔值* | 如果指定名称的变量存在于集合中，则返回 **True**，否则返回 **False**。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| 获取   | <字符串:名称>                  | *变体*  | <p>返回指定名称的变量的值。<br>您可以将此方法用作索引集合的替代方法。需要注意的一个区别是，此方法直接返回存储在变量中的 <em>值</em>。如果您需要包含值的 <a href="var.zh"><strong>Var</strong></a> 对象（例如，要调用 <strong>var.Delete</strong> 或更改 <strong>var.persist</strong>），则应改为索引集合。关于如何执行此操作的示例在下面的 <strong>Set</strong> 文档中。</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| 设置   | <p><字符串:名称><br><变体:值></p> | *无*   | <p>将指定名称的值设置为指定值。您可以将此方法用作索引集合的替代方法。</p><p>您可以在 <strong>Vars</strong> 集合中存储任何类型的变量，但并非所有类型都可保存到磁盘。如果您希望变量具有持久性，则应仅使用 <em>布尔值</em>、<em>整数</em>、<em>字符串</em>、<em>日期</em>、<em>货币</em> 或这些类型的 <a href="vector.zh"><strong>Vector</strong></a>。<br>变量在默认情况下不是持久性的。如果您需要它们在重启后保存，则需要明确请求。以下是在 VBScript 中的一个示例：<br>`Dim varName, varValue1, varValue2 varName = "MyVariableName"</p><p>if (DOpus.Vars.Exists(varName)) then varValue1 = DOpus.Vars.Get(varName) DOpus.Output varName &#x26; " = " &#x26; varValue1 else DOpus.Output varName &#x26; " does not exist yet." end if</p><p>varValue2 = "My Variable Value"</p><p>DOpus.Vars.Set varName, varValue2 DOpus.Vars(varName).persist = True`</p><p>以下是在 JScript 中的相同示例：<br>`var varName = "MyVariableName";</p><p>if (DOpus.Vars.Exists(varName)) { var varValue1 = DOpus.Vars.Get(varName); DOpus.Output(varName + " = " + varValue1); } else { DOpus.Output(varName + " does not exist yet."); }</p><p>var varValue2 = "My Variable Value";</p><p>DOpus.Vars.Set(varName, varValue2); DOpus.Vars(varName).persist = true;`</p><p>在第一次运行时，示例代码将显示变量不存在，并将该变量设置为一个值，并在之后开启持久性。如果再次运行，它将报告该变量的值，并且该值将在重启后保持持久性。</p> |


---

# Agent Instructions: 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://chaoses-ib.gitbook.io/directory-opus/guan-fang-shou-ce/readme.zh-10/readme.zh-3/readme.zh/vars.zh.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.
