From fa776105e6b3a857163099c736bc178af9f3bf05 Mon Sep 17 00:00:00 2001 From: bordun Date: Thu, 29 Oct 2020 11:39:27 +0100 Subject: [PATCH] script: set: affect only 1 widget if no wildcard is used --- resources/docs/docs/widgets/scripting.md | 5 +++-- src/client/widgets/scripts/script-vm.js | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/resources/docs/docs/widgets/scripting.md b/resources/docs/docs/widgets/scripting.md index e222d805..ff7c33c5 100644 --- a/resources/docs/docs/widgets/scripting.md +++ b/resources/docs/docs/widgets/scripting.md @@ -63,13 +63,14 @@ Returns the value of the first matching widget. ---- #### `set(id, value, options)` -- `id`: widget `id` as a string. Can be `"this"` to target the host widget, or `"parent"` to target the parent widget. `id` can contains wildcards ('\*'), in which case all matching widgets will be affected **except** the emitting widget. +- `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 ('\*'). - `value`: new value for the widget. - `options` (optional): `object`, accepts the following items: - `sync: false` (prevents widgets from triggering synchronization and scripts) - `send: false` (prevents widgets from sending osc messages) -Sets the value of matching widgets. +Sets the value of the first matching widget or, if `ìd` contains wildcards, affects all matching widgets **except** the emitting widget. + If the event that triggered the script's execution was initiated by a user interaction, this will make the widget send its value as well (unless `options` is set to `{send: false}`). ---- diff --git a/src/client/widgets/scripts/script-vm.js b/src/client/widgets/scripts/script-vm.js index a4d55f11..a18e10ef 100644 --- a/src/client/widgets/scripts/script-vm.js +++ b/src/client/widgets/scripts/script-vm.js @@ -78,7 +78,7 @@ class ScriptVm extends Vm { Object.keys(widgetManager.idRoute).filter(key => key.match(new RegExp('^' + id.replace(/\*/g, '.*') + '$'))) ).filter(w => w !== widget) } else { - widgets = this.resolveId(id) + widgets = this.resolveId(id).slice(0, 1) }