Issues with intervals and timeouts


#1

can someone tell me where my code is messed up here?

I want the two characters to blink randomly throughout all the scenes in the attachment. Initially, I ran the blink function on the first scene and hoped it would just continue throughout the remaining scenes. But that caused the second scene to restart itself.

So, then I tried running a function to clear the interval and added code to clear the timeouts each time the interval runs but that’s not solved it. When you click through from scene 2 to scene 3, the timeouts start again but the audio starts playing again because it appears that the scene restarts. This happens multiple times.

I’ve got a feeling I don’t know enough about how to use intervals and timeouts.

blinkingProblems.hype.zip (973.4 KB)


(Hans-Gerd Claßen) #2

i did not look in depth … but one thing i found is that your using timelines with the same name across scenes:

Timeline names are user-defined and uniqueness is not enforced. If you are going to use these functions, be sure that no two timelines in any scene have the same name.

source:

https://tumult.com/hype/documentation/3.0/#timeline-functions

however timelines within a symbol could be reused by calling the right symbol instance …


(Jonathan Deutsch) #3

The issue is that you do not have “BlinkH” and “BlinkW” timelines on Scenes 2 and 3, yet you are trying to play those in the blink function. (The wrong code path is coming through due to this and the main timeline is being replayed.)

You’ll want to add those timelines to the scenes that do not have them.

Alternatively, you may want to look into using symbols or persistent symbols for the eyes. These constructs are intended to cut down on the amount of work required - for example you can have a persistent symbol run the blink function once on symbol load and then it will carry through to all your scenes so you could potentially not call stop again if you wanted.


#4

thanks for the responses. I tried a persistent symbol on the left character’s eyelids. I deleted all other blink timelines from the doc and only have a timeline for blinkH in the symbol. I animate the eyes open and then call the script to start the interval for blinking.

Whenever the interval that sets the timeout on the timeline is called, the log shows that it restarts the scene precisely when it should be running the blinkH timeline. And the screen goes black with the audio continuing for about half a second before the scene restarts.

Why it does this, I have no idea. I mean, I can imagine it doing nothing, but it’s a mystery to me why Hype would interpret any error here to mean, restart the main timeline of the scene.

blinkingProblems2.hype.zip (854.1 KB)


#5

I’ve managed to get it working by duplicating the timelines for each scene and triggering them separately, calling them by using the scene name as a variable.

I think my original issues were a combination of not having the timelines on each scene and also not having consistent case on the timeline names and in my function.

here’s a working copy

blinkingProblems3.hype.zip (857.3 KB)

Still very interested to know what’s causing the issues in version 2 above with the symbol.


(Jonathan Deutsch) #6

I did some code research and it looks like there was silly historic reason that would default to the main timeline if the requested one wasn’t found. This behavior will be changed for v4.0.0.

The fundamental issue on why blinking was not working in blinkingProblems2 is that you are using:

hypeDocument.startTimelineNamed('blinkH', hypeDocument.kDirectionForward)

But the hypeDocument.startTimelineNamed() API references timelines on the top-level scene.

In order to run timelines within a symbol, you need to use the symbol-based APIs. In the context of your code, it would look something like:

var symbolInstance = hypeDocument.getSymbolInstanceById(element.id);
symbolInstance.startTimelineNamed('blinkH', hypeDocument.kDirectionForward);

(the element of a timeline action is the symbol DOM element; this ID is thus supplied to the first call)