Execution of script

Hi,

I think I miss sth about the usage of script.

Let’s explain my expectations.
I would like to execute a script when i press on a push button to copy current value of some faders in other ones.
I created a script and a push button and set the same osc address. Moreover i bypassed the script osc to avoid sending message when a command is received from the button (i tried to put ‘>> scriptId’ in the linkId field of the button but the script was not executed).

With the dual osc address config it works but since the moment i pressed on the button, the script is called every time i change the origin fader value into the copy fader value…
I think it’s because i miss somethong about the comprehension of script

Here is the code of my script :slight_smile:
JS{{
var fader = “preset_”+ @{parent.variables.n} + “"
+ @{parent.variables.p} + “fader” ;
var enable = "preset
” + @{parent.variables.n} +
“_” + @{parent.variables.p} + “enable”;
var _fader = fader + 0;
var _enable = enable + 0;
var _speed = @{server_0_velocity_fader};
var _enabled = @{server_0_enable};
set(_fader, _speed);
set(_enable, _enabled);
_fader = fader + 1;
_enable = enable + 1;
_speed= @{server_1_velocity_fader};
_enabled = @{server_1_enable};
set(_fader, _speed);
set(_enable, _enabled);

_fader = fader + 2;
_enable = enable + 2;
_speed= @{server_2_velocity_fader};
_enabled = @{server_2_enable};
set(_fader, _speed);
set(_enable, _enabled);

_fader = fader + 3;
 _enable = enable + 3;
_speed= @{server_3_velocity_fader};
_enabled = @{server_3_enable};
 set(_fader, _speed);
 set(_enable, _enabled);
}}

Note : this widget is cloned with different id (thks to variables.n and variable.p values) but i think it dosen’t matter but i mention it.

Morevore i meet some troubles to use a variable in a widget name, i would like to use a ‘for loop’ but i didn’t manage to interpret a variable in the container @{} what is the syntax for using variable inside it for exemple what would be the syntax if would like to use i variable in @{widget_i_exampe}.

Have a good day.

the script is called every time i change the origin fader value

If the script is executed then it receives a value, either from

  • a same-id sync
  • a linkId sync
  • an update in its value property
  • an osc message

Did you write your code in the script property ?

Here is a recent topic on how scripts are executed that might help too: Example of script triggered by value rather than by LinkId?

Morevore i meet some troubles to use a variable in a widget name, i would like to use a ‘for loop’ but i didn’t manage to interpret a variable in the container @{} what is the syntax for using variable inside it for exemple what would be the syntax if would like to use i variable in @{widget_i_exampe}.

You can’t do that, @{} calls are resolved to variables before the script is parsed, a get(id) function would be nice, I’ll add that .

get(id) in scripts will be included in next release.

ok thanks, waiting for the next release to test the get(id) function :slight_smile:

Now i get some troubles with the condition field, which seems to have no effect, what is the way to run only the script when the received value (from osc) is at 1, isn’t it ‘value == 1’ ?

The second problem I meet is that the script are always executed on boot of new instance, but I think I could avoid it with the condition field and a default value that avoid to call the script.

Thks

Can you paste the exact content of your condition property ?

Just a simple ‘value == 1’, but I think it’s not that way.

Indeed, you need to wrap it in a JS{{}} or #{} tag.

Now the condition property became pretty much obsolete with the JS syntax, since you could simply add this line at the beginning of your script (after “JS{{”):

if (value != 1) return

ok, got it, now it works as well.