# Vars

The **Vars** object represents a collection of user and script-defined variables. There are a number of different sets of variables, with differing scopes. Some sets support persistent variables, that are saved and re-loaded from one session to the other.

| Scope   | Accessed by                                                                                                                                                     | **Supports Persistence** | Description                                                                                                                                          |
| ------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
| Global  | [**DOpus**](https://chaoses-ib.gitbook.io/directory-opus/manual/reference/scripting_reference/scripting_objects/dopus)**.vars**                                 | Yes                      | Variables that are available throughout Opus. They can be accessed by any function or script.                                                        |
| Lister  | [**Lister**](https://chaoses-ib.gitbook.io/directory-opus/manual/reference/scripting_reference/scripting_objects/lister)**.vars**                               | Yes                      | Variables that are local to a Lister. Persistent variables are saved on a per-Lister basis in Lister Layouts.                                        |
| Tab     | [**Tab**](https://chaoses-ib.gitbook.io/directory-opus/manual/reference/scripting_reference/scripting_objects/tab)**.vars**                                     | Yes                      | Variables that are local to a particular tab. Persistent variables are saved per-Tab in Lister Layouts.                                              |
| Script  | <p><a href="script"><strong>Script</strong></a><strong>.vars</strong><br><a href="scriptinitdata"><strong>ScriptInitData</strong></a><strong>.vars</strong></p> | Yes                      | Variables that are local to a particular script add-in.                                                                                              |
| Dialog  | [**Dialog**](https://chaoses-ib.gitbook.io/directory-opus/manual/reference/scripting_reference/scripting_objects/dialog)**.Vars**                               | Yes                      | Variables that are tied to a particular [script dialog](https://chaoses-ib.gitbook.io/directory-opus/manual/scripting/script_dialogs).               |
| Command | [**Command**](https://chaoses-ib.gitbook.io/directory-opus/manual/reference/scripting_reference/scripting_objects/command)**.vars**                             | No                       | Variables that are local to a particular function. They are not saved from one invocation of the function to another and do not support persistence. |

| Property Name      | Return Type                                                                                                                     | Description                                                                                                                                                                                                                                                                                                                             |
| ------------------ | ------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *\<default value>* | *collection:*[**Var**](https://chaoses-ib.gitbook.io/directory-opus/manual/reference/scripting_reference/scripting_objects/var) | Returns a collection of the variables in the collection. You can enumerate the [**Var**](https://chaoses-ib.gitbook.io/directory-opus/manual/reference/scripting_reference/scripting_objects/var) elements or refer to a specific one by its index or by its name. An example of how to do that is in the **Set** documentation, below. |

| Method Name | **Arguments**                             | Return Type | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| ----------- | ----------------------------------------- | ----------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Delete      | \<string:name>                            | *none*      | Deletes the named variable from the collection. You can also specify a [wildcard pattern](https://chaoses-ib.gitbook.io/directory-opus/manual/reference/wildcard_reference/pattern_matching_syntax) to delete multiple variables (or \* for all).                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| Exists      | \<string:name>                            | *bool*      | Returns **True** if the named variable exists in the collection, or **False** if it doesn't exist.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| Get         | \<string:name>                            | *variant*   | <p>Returns the value of the named variable.<br>You can use this method as an alternative to indexing the collection. One difference to note is that this method directly returns the <em>value</em> stored in the variable. If you need the <a href="var"><strong>Var</strong></a> object which contains the value (for example, to call <strong>var.Delete</strong> or change <strong>var.persist</strong>) then you should index the collection instead. An example of how to do that is in the <strong>Set</strong> documentation, just below.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| Set         | <p>\<string:name><br>\<variant:value></p> | *none*      | <p>Sets the named value to the specified value. You can use this method as an alternative to indexing the collection.</p><p>You can store any type of variable in a <strong>Vars</strong> collection, although not all types can be saved to disk. If you want your variable to be persistent you should only use <em>bool</em>, <em>int</em>, <em>string</em>, <em>date</em>, <em>currency</em> or a <a href="vector"><strong>Vector</strong></a> of those types.<br>Variables are not persistent by default. If you need them to be saved across a restart, you need to request it explicitly. Here is an example in 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>Here is the same example in 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>On the first run, the example code will say the variable does not against and set it to a value, turning on persistence afterwards. If it is then run again, it will report the variable's value, and the value will persist across a restart.</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/manual/reference/scripting_reference/scripting_objects/vars.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.
