Problem: loop a scene in js

Hello,

i’m new in hype and I have a question.

I have a scene containing a movie (ID ‘video1’)
At specific times (2 seconds, 5 seconds, 9 seconds) time axis (info1_start_button, info2_start_button, info3_start_button) start.

This is the code:

function js_scene(hypeDocument, element, event) {
	
// This establishes the T1 variable as an integer.
var T1 = 0;
var T2 = 0;
var T3 = 0;

// Listen to the 'timeupdate' value: 
hypeDocument.getElementById('video1').addEventListener('timeupdate', function() {
var currentTime = hypeDocument.getElementById('video1').currentTime;

// if the current time is greater than 2, run the info1 timeline. 
if (currentTime >= 2 && T1 == 0) {
hypeDocument.startTimelineNamed('Info1_start_button');

// This ensures that the 'startTimelineNamed' action only occurs once, not at every point beyond time = 13. 
T1 = T1 + 1;
}

// if the current time is greater than 5, run the info2 timeline. 
if (currentTime >= 5 && T2 == 0) {
hypeDocument.startTimelineNamed('Info2_start_button');

// This ensures that the 'startTimelineNamed' action only occurs once, not at every point beyond time = 24. 
T2 = T2 + 1;
}

// if the current time is greater than 9, run the info3 timeline. 
if (currentTime >= 9 && T3 == 0) {
hypeDocument.startTimelineNamed('Info3_start_button');

// This ensures that the 'startTimelineNamed' action only occurs once, not at every point beyond time = 37. 
T3 = T3 + 1;
}


});

}

Everything works fine for the first time I play the scene in a browser. But when I loop the scene the time axis doesn’t start from second loop.
I think I do not have to loop in hype but in the java script.
I think I have to tell hype in the script that for example after 20 seconds the scene shall be repeated. But how can i do this?

Thanks a lot

If you run this 'on scene load' then you would need to have your loop actually do a scene transition back to reload the same scene. If you run this function as a timeline action at time 0, then the initial values like T1, T2, T3 would get reset back to 0 at the start.

var T1 = 0; var T2 = 0; var T3 = 0;

These variables are not reset. Also every time when you revisit the scene your adding another event listener. You should remove the event listener on scene unload. Another hint that might help is putting your status into hypeDocument.customData.T1 etc. this way it’s persistent across functions. Then you can reset them with a timeline action like hypeDocument.customData.T1 = 0; etc.