Hey guys, I have this timer, that I would like to save the current scene's name in a global var after 10 minutes to remember the scene I am in at the moment.
What I am trying is:
timer_10_mins = setTimeout( function () {
window.current_scene = HYPE.documents['document_name'].currentSceneName();
}, 600000)
and it is not working. I am doing something wrong here?
If this is within Hype, you would use:
window.current_scene = hypeDocument.currentSceneName();
But your code looks correct for usage outside of Hype as long as document_name
matches the name used during export.
You should also be able to put this in the Hype Projects HEAD
<script type="text/javascript"> function myCallback(hypeDocument, element, event){
window.myhypedocument = hypeDocument;
timer_10_mins = setTimeout( function () {
window.current_scene = hypeDocument.currentSceneName();
console.log(window.current_scene)
}, 600000)
}
if("HYPE_eventListeners" in window === false) {
window.HYPE_eventListeners = Array();
}
window.HYPE_eventListeners.push({"type":"HypeDocumentLoad", "callback":myCallback});
</script>
Which will save you having to remember to use the correct document name.
Also window.myhypedocument there to give you access to the hype runtime if you need it.
Or why wait ten mins to store what scene you are on.
You can also change it to a on scene load.
<script type="text/javascript"> function myCallback(hypeDocument, element, event){
if (typeof window.myhypedocument == "undefined"){ window.myhypedocument = hypeDocument;}
window.current_scene = hypeDocument.currentSceneName();
console.log(window.current_scene)
}
if("HYPE_eventListeners" in window === false) {
window.HYPE_eventListeners = Array();
}
window.HYPE_eventListeners.push({"type":"HypeSceneLoad", "callback":myCallback});
</script>
Which stores the scene name when you change scene.
3 Likes
Thank you @MarkHunte Exactly what I've been looking for, thanks a lot!
1 Like