performing function in 'while' loop

Discuss Lemur and share techniques.
Post Reply
shanekoss
Newbie
Posts:26
Joined:27 Jun 2012 13:27
performing function in 'while' loop

Post by shanekoss » 15 Dec 2013 00:35

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;
}
}

oldgearguy
Regular
Posts:315
Joined:02 Nov 2013 11:19

Re: performing function in 'while' loop

Post by oldgearguy » 15 Dec 2013 12:11

First question is what condition is triggering the Script? X? 'On any'?

shanekoss
Newbie
Posts:26
Joined:27 Jun 2012 13:27

Re: performing function in 'while' loop

Post by shanekoss » 15 Dec 2013 14:05

Yes, triggered on x.

oldgearguy
Regular
Posts:315
Joined:02 Nov 2013 11:19

Re: performing function in 'while' loop

Post by oldgearguy » 15 Dec 2013 14:54

I thought the time function was in milliseconds, not seconds. So the initial wait condition should probably be adding 2000, not 2, right?

shanekoss
Newbie
Posts:26
Joined:27 Jun 2012 13:27

Re: performing function in 'while' loop

Post by shanekoss » 15 Dec 2013 16:36

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.

electrofux
Regular
Posts:297
Joined:24 Jan 2012 18:22

Re: performing function in 'while' loop

Post by electrofux » 16 Dec 2013 00:56

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.

Softcore
Regular
Posts:1639
Joined:04 Nov 2012 08:34

Re: performing function in 'while' loop

Post by Softcore » 16 Dec 2013 08:02

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.

shanekoss
Newbie
Posts:26
Joined:27 Jun 2012 13:27

Re: performing function in 'while' loop

Post by shanekoss » 16 Dec 2013 13:48

@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!

Post Reply