# ScriptOnlyVariables

ScriptOnlyVariables系统变量用于定义脚本专用变量。此变量指定脚本变量是仅在脚本中可用，还是在脚本外部也可用（和可见）—例如，在应用程序的工作表视图中。

在定义了 ScriptOnlyVariables 值之后 —无论是显式定义，还是通过其默认值 0 隐式定义— 在此定义之后，在 Let 或 Set 语句中定义的所有变量都将使用定义的设置，除非 ScriptOnlyVariables 值在脚本后面被更改。这意味着您可以将某些变量定义为仅限脚本，并允许其他变量在脚本外部显示。

语法：

ScriptOnlyVariables

`ScriptOnlyVariables`ScriptOnlyVariables 值

| 值 | 结果 |
| --- | --- |
| `0` | 变量在脚本外部显示，此外在脚本本身中也可用。<br><br>这是默认值，如果 ScriptOnlyVariables 变量值未在脚本中显式定义。 |
| `1` | 变量不会在脚本外部显示。 |

示例 1: 在脚本外部显示变量

在此示例中，变量 `vNotScriptOnly` 被明确设置为在脚本外部显示。

```
SET ScriptOnlyVariables = 0;
SET vNotScriptOnly = "example_text";
```

示例 2: 在脚本外部隐藏变量

在此示例中，变量 `vScriptOnly` 将仅在脚本执行期间可用。它不会在其他地方显示，例如工作表视图。

```
SET ScriptOnlyVariables = 1;
SET vScriptOnly = "example_text";
```

示例 3: 隐藏一些变量并显示其他变量

在此示例中，ScriptOnlyVariables值在整个脚本中多次定义，以允许不同的变量设置。变量`vHideOutsideScript`仅在脚本执行期间可用。变量`vAllowInSheets`将显示在工作表视图中。

```
SET ScriptOnlyVariables = 1;
SET vHideOutsideScript = "example_text";
SET ScriptOnlyVariables = 0;
SET vAllowInSheets = "example_text";
```

## 适合使用 ScriptOnlyVariables 的情况

仅限脚本的变量可帮助您：

* 仅在数据模型的上下文中，使用某些变量执行计算和字段定义。

* 移除创建工作表和图表不需要的变量，从而简化应用程序开发。

## 了解详情

* [系统变量](https://help.qlik.com/zh-CN/cloud-services/Subsystems/Hub/Content/Sense_Hub/Scripting/SystemVariables/system-variables.htm)
* [Let](https://help.qlik.com/zh-CN/cloud-services/Subsystems/Hub/Content/Sense_Hub/Scripting/ScriptRegularStatements/Let.htm)
* [Set](https://help.qlik.com/zh-CN/cloud-services/Subsystems/Hub/Content/Sense_Hub/Scripting/ScriptRegularStatements/Set.htm)
* [在数据加载编辑器中使用变量](https://help.qlik.com/zh-CN/cloud-services/Subsystems/Hub/Content/Sense_Hub/Scripting/work-with-variables-in-data-load-editor.htm)