docs: VAR{}, getVar, setVar
This commit is contained in:
parent
fbc2eda1cd
commit
b56d05713d
3 changed files with 23 additions and 2 deletions
|
|
@ -56,10 +56,14 @@ Options can contain `@{}` blocks.
|
|||
}}
|
||||
```
|
||||
|
||||
## Custom variables: `VAR{variableName, default}`
|
||||
|
||||
This syntax creates a custom variable in the widget that can be read and modified from any widget's `script` property (see [scripting](./scripting.md#getvarid-name)). Changes made to this variable will be applied automatically.
|
||||
|
||||
|
||||
## Javascript: `JS{{ <code> }}`
|
||||
|
||||
This syntax allows writing formulas in [Javascript](https://developer.mozilla.org/en-US/docs/Web/JavaScript). The code will be compiled as a function and executed in a restricted context.
|
||||
This syntax allows defining a property using [Javascript](https://developer.mozilla.org/en-US/docs/Web/JavaScript). The code will be compiled as a function and executed in a restricted context.
|
||||
|
||||
- if no `return` statement is found, the formula will return an empty string
|
||||
- javascript [strict mode](https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Strict_mode) is always enabled
|
||||
|
|
|
|||
|
|
@ -109,6 +109,23 @@ If the event that triggered the script's execution was initiated by a user inter
|
|||
|
||||
----
|
||||
|
||||
#### `getVar(id, name)`
|
||||
- `id`: widget `id` as a string.
|
||||
- `name`: variable name as a string.
|
||||
|
||||
Returns the value of a widget's custom variable.
|
||||
|
||||
----
|
||||
|
||||
#### `setVar(id, name, value)`
|
||||
- `id`: widget `id` as a string. Can be `"this"` to target the host widget, or `"parent"` to target the parent widget. `id` may contains wildcards ('\*').
|
||||
- `name`: variable name as a string.
|
||||
- `value`: new value for the variable.
|
||||
|
||||
Sets the value of a widget's custom variable. If `ìd` contains wildcards, affects all matching widgets.
|
||||
|
||||
----
|
||||
|
||||
#### `send(target, address, ...args)`
|
||||
- `target` (optional): `"ip:port"` or `"midi:device_name"` string. If omitted, the widget's target will be used.
|
||||
- `address`: osc address, must start with a `/`
|
||||
|
|
|
|||
|
|
@ -384,7 +384,7 @@ class ScriptVm extends Vm {
|
|||
|
||||
for (var imports of ['set', 'get', 'getProp', 'getIndex', 'updateProp', 'send', 'httpGet', 'stateGet', 'stateSet', 'storage',
|
||||
'setInterval', 'clearInterval', 'setTimeout', 'clearTimeout', 'setFocus', 'unfocus', 'setScroll', 'getScroll', 'toolbar',
|
||||
'openUrl']) {
|
||||
'openUrl', 'getVar', 'setVar']) {
|
||||
this.sanitize(this.sandbox.contentWindow[imports])
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue