setTimeout usage

I'm playing with timeout :

I put this script in a variable that is set to 1 by a script in a button.

if (value==1) {
    function endclear() {
        // do stuff at time out
        console.log("clear stopped");
    }
    // do stuff at time in
    setTimeout(endclear, @{vMeasure});
    console.log("clear start : @{vMeasure}");
    set("this",0);
}

( @{vMeasure} defines delay in ms )
I get the start but not the stop.
What am I doing wrong ?

Nothing wrong, this piece of works here. But don't use @{} in scripts, use get() instead (Scripting - Open Stage Control)

1 Like

Still doesn't work after changing to get() and getProp().
I switched strategy and went for a midiclock count which I implemented, checking above a certain count.
Still doesn't work.

The part that doesn't work, in the "do stuff at time out", is actually using various send() to send midi cc.
And I just reread the "send()" documentation and I quote:

If the event that triggered the script's execution was not initiated by a user interaction, this function will have no effect.

So I think this is what doesn't work.

How can i send() midi messages by script without user interaction ?

1 Like

Can you upload a minimal session to reproduce your issue please ?

If the setTimeout is caused by a user interaction then the message sends.

How can i send() midi messages by script without user interaction ?

The script widget has a mode called once that runs the script right after it's parsed (at session load or everytime the property is edited). Otherwise, your must write a custom module.

1 Like

I'm trying to setup a minimal session to reproduce the issue.

If I go the custom module way, how can I trigger a specific function in the custom module with the widget ? Should I export that specific function along with "init", "oscInFilter", etc. functions, and will it be available for every widget ?

1 Like

If I go the custom module way, how can I trigger a specific function in the custom module with the widget

Triggering something with a widget is a user interaction, there should be no problem sending messages from scripts executed that way.

The usual way to trigger something in the custom module with a widget is to send an osc message, and catch it in the custom module's oscOutFilter function.

and will it be available for every widget ?

No, the custom module will just be able to filter incoming/outgoing messages, it can only communicates with the client app using osc messages

2 Likes