Skip to main content
Participating Frequently
June 24, 2022
Question

LoopOut stop at certain time

  • June 24, 2022
  • 10 replies
  • 8357 views

I have a working loopOut and i'm trying to stop it at a certain time.

i tried:

timeToStop = 10; 
if (time > timeToStop) { 
value; 
} else { 
loopOut(); 
}

 

and also

 

if(time < 10){
loopOut()
}

else {
value
}

 

but both doesnt do the stopping trick, wel it stops right after one sequence...

What do I need to do to make this work? thanks!!

This topic has been closed for replies.

10 replies

Dan Ebberts
Community Expert
Community Expert
June 24, 2022

Both of those stop after 10 seconds for me, although it's not a very graceful stop unless the length of the loop goes evenly into 10.

Participating Frequently
June 24, 2022

Hi, dont know why, but it does stop now. But now i dont get it started at a certain time. But that will be for a new post.

 

Gracefully, no it is not. But this is a whole lot for me yet to get this working 😉 

 

Can you put me in a direction to search for a smooth stop?

Dan Ebberts
Community Expert
Community Expert
June 24, 2022

There are a number of different ways, but the simplest might be to either specify the number of loops, like this:

n = 3; // number of loops
if (numKeys > 1){
  t1 = key(1).time;
  t2 = key(numKeys).time;
  if (time < t1 + n*(t2-t1))
    loopOut()
  else
    key(numKeys).value;
}else
  value;

or, have it stop at the last full loop before your specified time:

timeToStop = 10;
if (numKeys > 1){
  t1 = key(1).time;
  t2 = key(numKeys).time;
  n = Math.floor((timeToStop - t1)/(t2 - t1));
  if (time < t1 + n*(t2-t1))
    loopOut()
  else
    key(numKeys).value;
}else
  value;