a bit perplexed on this one. have the following code in a Pad script to wait 2 seconds to perform a function. ztime and val are custom variables used to accomplish this.
The two note-outs are sent - but only after the pad is released (x=0). I would expect the note-out info to be sent while the pad is still held (x=1) and while (val=1).
Furthermore - it doesn't seem to call the manual function either until the pad is released.
any ideas? thanks!
if(x==1){ztime=time+2;val=1;}
while(val==1){
if(time>ztime){
noteout(0,80,127,1);
noteout(0,50,127,1);
val=0;
color();
break;
}
}
performing function in 'while' loop
-
- Regular
- Posts: 315
- Joined: 02 Nov 2013 11:19
Re: performing function in 'while' loop
First question is what condition is triggering the Script? X? 'On any'?
Re: performing function in 'while' loop
Yes, triggered on x.
-
- Regular
- Posts: 315
- Joined: 02 Nov 2013 11:19
Re: performing function in 'while' loop
I thought the time function was in milliseconds, not seconds. So the initial wait condition should probably be adding 2000, not 2, right?
Re: performing function in 'while' loop
i think the milliseconds are decimal - and that part works fine - the delay works. the problem is it only sends the value when x becomes 0. As long as x==1, nothing is sent.
-
- Regular
- Posts: 294
- Joined: 24 Jan 2012 18:22
Re: performing function in 'while' loop
i had a similar problem a while ago when i wanted to slow down a loop. I never succeeded with a normal loop. Instead i triggered a script with a time condition in the trigger field.
Re: performing function in 'while' loop
You cant actually hope for a delay with scripts dependent on expressions, they dont have a lifespan so to speak (well actually they have a pretty short one, the time required for them to be executed). The common misconception here is that the script is "active" so to speak while x==1 - which is not the case. The script is fired and executed, it does not "stay active".
In your case above, time will NEVER be greater than ztime for x==1 because once x==1, ztime = time +2, and then we are out of the execution for the rest part of the code. Think of reading the script as a "pass": x goes 1, ztime goes time +2, val goes 1, then there is a while and then there is a "if" which will not be evaluated (the "time" so to speak now, is only greater by the amount it took the script to execute the above 2-3 lines) and then we exit the script. The script will NOT be executed again untill x changes.
What happens then, as you release the pad, (remember, you have set the script to execute on x), is that ztime is not re-defined (it is re-defined, only if x==1), and now, after the release, time is indeed greater than ztime previously defined (when x was set to 1), hence the messages are sent and the custom function is called.
I can even predict that if you touch and let go fast enough the pad (faster than 2 milliseconds) the messages and custom function wont even work after the release.
(*note: The time Variable is a millisecond value you can use for creating time-varying behavior in Lemur, Lemur manual page 124)
On frame is the way to go.
In your case above, time will NEVER be greater than ztime for x==1 because once x==1, ztime = time +2, and then we are out of the execution for the rest part of the code. Think of reading the script as a "pass": x goes 1, ztime goes time +2, val goes 1, then there is a while and then there is a "if" which will not be evaluated (the "time" so to speak now, is only greater by the amount it took the script to execute the above 2-3 lines) and then we exit the script. The script will NOT be executed again untill x changes.
What happens then, as you release the pad, (remember, you have set the script to execute on x), is that ztime is not re-defined (it is re-defined, only if x==1), and now, after the release, time is indeed greater than ztime previously defined (when x was set to 1), hence the messages are sent and the custom function is called.
I can even predict that if you touch and let go fast enough the pad (faster than 2 milliseconds) the messages and custom function wont even work after the release.
(*note: The time Variable is a millisecond value you can use for creating time-varying behavior in Lemur, Lemur manual page 124)
On frame is the way to go.
Re: performing function in 'while' loop
@Softcore - thanks for the detailed reply! I thought i was getting around that by having x toggle another variable - but i can see now why it doesn't work! I was thinking having a bunch of scripts set to onFrame wasn't very efficient so was looking for an alternative.
cheers!
cheers!