Delay javascript function

Hi there,

Looking to delay the javascript below from running straight away, I imagine a setTimeout function could be combined to achieve this, just not sure how it would be added.

Any help greatly appreciated,

Thanks.

if (window.currentTimeForScene1 != null) {
	hypeDocument.goToTimeInTimelineNamed(window.currentTimeForScene1, 'Images');
	hypeDocument.pauseTimelineNamed('Images', hypeDocument.kDirectionForward);
} else { 

 
}

I did a forum search (always a good idea as it’s filled to the brim with past problems & solutions), for “delay javascript” and ran into this:

I’m not a JS guy, at all :sweat_smile: but my idea would be to use ^that code to stall a timeline where at some point your code will run.

So something like this: pause_timeline.hype.zip (14.9 KB)

3 Likes

The basic form for a delay is:

window.setTimeout(function () {

    /* place code here */

}, 2000); // 2000 is 2 seconds in milliseconds

I’ll also point out that this doesn’t necessarily need to be accomplished in code if you don’t want; you could make a new timeline (or, if appropriate, use an existing one) that has a timeline action to run your event at a specified time.

1 Like

Thanks for showing the layout of the code.

Will get this added into the project.

Thanks again.

1 Like