Page 1 of 2

How to switch scripts on and off

Posted: 06 Oct 2012 01:08
by jbgeluid
Is there a way to switch scripts on and off with buttons? I did read the manual...

Re: Switch scripts on and off

Posted: 06 Oct 2012 01:49
by brianc
You could create a variable called run_script or something, and start those scripts with:

Code: Select all

if(!run_script) return;
Then just set run_script to 1 when you want it to run, and 0 otherwise.

Re: How to switch scripts on and off

Posted: 09 Oct 2012 12:39
by jbgeluid
brianc,

thanks for your reply, but can you be more specific? I'm a beginner, sorry..

Re: How to switch scripts on and off

Posted: 09 Oct 2012 12:59
by Macciza
Hi
Brianc has shown a way for scripts to only run if the run_script variable is set - say by a switch
This lets you have a script for say an object that will only run when the flag is set - say by using a Switch or set from another script

If you mean run a script in response to a switch set the script up to execute On Expression and Switch.x (or whatever) to use your switch to run it . .
Cheers
MM

Re: How to switch scripts on and off

Posted: 09 Oct 2012 15:25
by brianc
jbgeluid wrote:brianc,

thanks for your reply, but can you be more specific? I'm a beginner, sorry..
Sure, here's an example template that (I hope) demonstrates how this can be done.

Re: How to switch scripts on and off

Posted: 09 Oct 2012 22:37
by Phil999
excellent. So simple.

Now, what if you don't have a switch as 'trigger', but a Knob object? A Fader object has a 'touch'-variable z, but the Knob object not. Is it possible to fake a z variable with a Knob object? For example, when Knob.x increases or decreases? How to you express that? Or is there a simpler method?

Code: Select all

if (Knob.x ++) return;
if (Knob.x --) return;
The code is wrong, but you probably understand what it should do. If Knob.x changes, return (don't continue with the script). If Knob.x remains the same, continue with the script.

Re: How to switch scripts on and off

Posted: 09 Oct 2012 22:53
by brianc
Phil999 wrote:Now, what if you don't have a switch as 'trigger', but a Knob object? A Fader object has a 'touch'-variable z, but the Knob object not. Is it possible to fake a z variable with a Knob object? For example, when Knob.x increases or decreases? How to you express that? Or is there a simpler method?
It's a little ugly, but I guess my approach would be to have a script that runs whenever Knob.x changes that updates a variable that stores the time at which the value was last changed. So something like:

Code: Select all

last_change = time;
Then in the script that was dependent on that knob activity, you could put something like:

Code: Select all

if(time - Knob.last_change > 2) return;
Which will disable that script if the knob hasn't been changed in the last 2 seconds. With a really small threshold, you can have this be sensitive to within a few milliseconds.

Re: How to switch scripts on and off

Posted: 09 Oct 2012 23:41
by Phil999
good idea. I tried it out, it doesn't work yet, but using a variable, and an expression-x-script for the 'trigger'-knob is a good method.

I also tried a variable (touch) and two scripts (touch_on, touch_off), but this also didn't work yet.

It shouldn't be too difficult, I'll get it soon I guess. Thank you for your help, very appreciated.

Re: How to switch scripts on and off

Posted: 10 Oct 2012 00:07
by jbgeluid
Thanks Brianc and Phil999 for your input! This realy helps.

Jurgen

Re: How to switch scripts on and off

Posted: 10 Oct 2012 01:55
by Phil999
brianc wrote:

Code: Select all

if(time - Knob.last_change > 2) return;
Which will disable that script if the knob hasn't been changed in the last 2 seconds. With a really small threshold, you can have this be sensitive to within a few milliseconds.
I want to disable the script when the knob changes, so it's

Code: Select all

if(time - Knob.last_change < 2) return;
That is working. Very nice.

Unfortunately, the script I want to prevent being executed does receive MIDI and moves the 'trigger'-knob - I'm running again in a feedback loop, something I wanted to prevent in the first place. My fault, I didn't expect that. I have to rethink this matter ...

Thanks again, your method is working.

My problem is described here:
http://liine.net/forum/viewtopic.php?f=25&t=1732