Conditions with scene names

Hello,
I’m trying to create a script that offers the possibility to play with scene names conditions. Let’s say there’s 3 scenes called A, B and C. The last one ‘C’ has 2 timelines called a and b which are played simultaneously on the main timeline. The idea is that if I come from the scene B and go to the C, only the timeline b should be played.
To get you a better picture, it would be like creating a playbook with multiple choices on every scenes.

As I’m beginner in Javascript and Hype, you must excuse me if this question is trivial. Nonetheless I found no comparable questions in your forums.

Thank you in advance for your answer.
Cheers, Quentin

You would need to store the last scene somewhere, in a global var, or sessionStorage, or Window storage.

then on each sceneLoad, you would add a function saying:

hypeDocument.startTimelineNamed(sessionStorage.getItem('cscene'), hypeDocument.kDirectionForward);

while at the same time updating the new scene name:

sessionStorage.setItem('cscene', hypeDocument.currentSceneName());

Hope that helps :slight_smile:

1 Like

it’s some efford, but you can work with custom behaviours that are triggered on any event.
That’s the approach of hype to built some logic without scripting.

Actually, there's a simple way to do that without coding.
For each scene, you need to create a custom behavior that triggers each timeline.

Exemple :
If, coming from scene A you need to trigger timeline 1 from scene B :

  • Scene B :
    Create custom behavior that triggers timeline 1 from this scene

  • Scene A :
    on click button :

jump to scene A
trigger custom behavior created on scene B

See encloses exemple file

CallActionNextScene.hype.zip (27.2 KB)

Can you explain how this fits with his needs for me.

You have only one scene, so I do not see how 4 scenes, which I assume any of them could be opened in any order, how it knows what timeline to start. Might be just me, and of course perhaps Custom Behaviours are simpler, but I cannot see it.

OK, here’s an exemple with two scenes. Try to adapt to what you need.

PlayDifferent.hype.zip (30.2 KB)

Okay, I am honestly not being funny, but I do not understand what you are doing. Based on the OP, he wants to play a timeline based on the scene previous. So in your example, the idea is, when the user presses the button which takes him to a new scene, it then fires a timeline?

So if the user is on Scene 4, and clicks to visit Scene 2, how will the button know to play the timeline Scene 2, and if the user is on Scene 4 and wants to visit Scene 3, it would need to be a different button, unless he uses the Next / Previous option.

I have never used Custom Behaviours, probably because I have never needed them, but i do not understand the need for them in this instance, hence my questions. I am trying to learn the reason for them :smile:

OK, ket me try to explain :

So in your example, the idea is, when the user presses the button which takes him to a new scene, it then fires a timeline?

That's it

So if the user is on Scene 4, and clicks to visit Scene 2, how will the button know to play the timeline Scene 2

It will because you tell it to do so. Button on scene 4 has two actions : jump to scene 2 + play timeline

and if the user is on Scene 4 and wants to visit Scene 3, it would need to be a different button, unless he uses the Next / Previous option.

Yes. Going to scene 2 needs a button and going to scene 3 needs another one. The same button can't lead to different scenes (unless it is a next/previous button, which my example doesn't involve)

Custom behaviors is here needed because it's the only way from a scene to trigger a timeline in another scene.

Only other way other than using 2 lines of code :wink:

hypeDocument.startTimelineNamed(sessionStorage.getItem('cscene'), hypeDocument.kDirectionForward);
sessionStorage.setItem('cscene', hypeDocument.currentSceneName());

Which seems much less complex than using Custom Behaviours ?

It certainly does to someone who masters code like you do ! But I’m not that gifted :wink:
Could you post any .hype doc to see how it is implemented ?

TimelineByScene.hype.zip (81.2 KB)

Thanks for the exemple. I managed to do one myself using your advice but yours is more detailed.
What’s the purpose of the script SetSceneName ? Apparently, it’s empty.
Is there a way to create a button leading to last visited scene according to visit history ?

I used it to set Scene A, while i was testing, Then I just duplicated the scenes and removed it.

And yeah, there are a few ways to create a history using sessionStorage or window as an array.

So I can delete it everywhere including in the library ?
Thanks for the tip for history

Yes, it was only used for dev testing and i removed the script, thinking it would remove the function :smile:

Hey Guys,
Thanks a lot for your answers, I could work my way through with both of your solutions !