Loop timeline with JS not working

Loop a timeline without JS is no problem.
But this code:

 multiBpmIntro[bpmi][4].play();
    multiBpm[bpm][4].play({ wait: multiDelayIntro[mdi][4], loop: true });
    //multiBpm[bpm][4] speelt backing track
    setTimeout(function () {
      hypeDocument.continueTimelineNamed('bpm145', hypeDocument.kDirectionForward, false)
    }, 2000);
    
    
    setTimeout(function () {

      hypeDocument.goToTimeInTimelineNamed(5 + 29/30, 'bpm145')
          hypeDocument.continueTimelineNamed('bpm145', hypeDocument.kDirectionForward, false);

    }, 10000);
    
  setTimeout(function () {

      hypeDocument.goToTimeInTimelineNamed(9 + 29/30, 'bpm145')
         hypeDocument.continueTimelineNamed('bpm145', hypeDocument.kDirectionForward, false);

    }, 18000);



  setTimeout(function () {

      hypeDocument.goToTimeInTimelineNamed(13+29/30, 'bpm145')
         hypeDocument.continueTimelineNamed('bpm145', hypeDocument.kDirectionForward, false);

    }, 26000);

            styleElements(".btn5Prog", "color", "#73FDFF");      
console.log(to);

runs the timeline, but will not start again. What is wrong?
I need to do it this way, because I need to vary the time between the markers on the timeline.
There are markers on time 2, 6 and 10 where a function is being called.
The last marker on time 14: goToTimeInTimeline(2, 'bpm145')
If there is a smarter solution: you're welcome to share

I assume:

hypeDocument.continueTimelineNamed('bpm145', hypeDocument.kDirectionForward, true)
    }, 2000);

... will do the job...

1 Like

Thanks for your answer Kalle, but that doesn't work.

edit: Hold on, I'm one step further.
No, didn't work.

I also have a full JS script. Working great until using the stopLoop function. The script doen't start after stopping but continues where it has been stopped.

	


// Control flag to determine if the loop should continue
 window.continueLoop = true;



	
	// Function 1: Executes first
function functionOne() {
 if (!continueLoop) return; // Stop the loop if the flag is false
    console.log("Function One is triggered!");
    // Your custom code for functionOne

 
    hypeDocument.functions().dorian(hypeDocument, element, event);

    // Call the next function after 3 seconds
    setTimeout(functionTwo, delay[bpm][to]);
        console.log(delay[bpm][to]);

}

// Function 2: Executes after Function 1
function functionTwo() {
 if (!continueLoop) return; // Stop the loop if the flag is false
    console.log("Function Two is triggered!");
    // Your custom code for functionTwo
     hypeDocument.functions().mixo(hypeDocument, element, event);

    // Call the next function after 2 seconds
    setTimeout(functionThree, delay[bpm][to]);
        console.log(delay[bpm][to]);

}

// Function 3: Executes after Function 2, then loops back to Function 1
function functionThree() {
 if (!continueLoop) return; // Stop the loop if the flag is false
    console.log("Function Three is triggered!");
    // Your custom code for functionThree
  
    hypeDocument.functions().major(hypeDocument, element, event);

    // Restart the sequence after 5 seconds
    setTimeout(functionOne, delay[bpm][to]);
        console.log(delay[bpm][to]);

}


// Start the loop
functionOne(); // Initially start the sequence

// Function to stop the loop
function stopLoop() {
    continueLoop = false;
  //console.log("Loop has been stopped.");
}
	

ChatGPT :grinning:
But I prefer the timeline version.

It is hard to say without seeing more of the document (feel free to post if you still need help) but I'll at least point out that you'd want to use setInterval to continue having something run instead of setTimeout which only runs once. Alternatively you'd need something in the current code to call back to itself somehow so it continues looping.

Here's a simplified version of what I'm trying to achieve. The timeline returns to time 2, but doesn't continue.
loop timeline.zip (15.9 KB)
tia

If I understand your approach correctly: You initially set the timeline to second 2, and from there, the timeline is advanced at specific times using a timeout function, at which points a script is triggered to change the color of the square. The issue, as I see it, lies in the fact that controlTempo is only called once. If you reset the timeline to second 2 (red) at the end, you obviously need to restart this function (which I'm doing now in the last frame). To prevent the first step of the function from being executed again, I set a variable 'endOfTimeline' to true at the end (blue).

Did I understand that correctly?

loop timeline_kt.zip (20.7 KB)

1 Like

Nice, the loop is working. Good job. Thank you.
This really helps me a lot.
I'll implement it in my project and will let you know the result.

edit
oops, the stop button doesn't work anymore.