docs: VAR{}, getVar, setVar

This commit is contained in:
bordun 2021-05-01 17:08:32 +02:00
parent fbc2eda1cd
commit b56d05713d
3 changed files with 23 additions and 2 deletions

View file

@ -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

View file

@ -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 `/`