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
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.");
}
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.
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).