[SOLVED 11-08-17] Return To Last Visited Scene Then Auto Jump Forward +1 Scene


(Stephen G) #1

Hi i found this post by @Daniel and it works great to return to the scene last visited BUT is it possible to increment that var by one to jump to the scene after the scene last visited?

I am creating a quiz that jumps to a new scene if the user scores 3,5,10,15 questions correct in a row giving them some feedback.

Currently when this animation plays it returns to the scene last visited HOWEVER they have already answered that question so the quiz stalls.

I need to force the app to jump to the last viewed scene plus one scene so that the next question can start. (Only JS will work as I want to keep changes to a minimum)

Thanks in advance!
@STE2DG


#2

Can’t really give you a definitive answer as we are unaware as to how you’ve named your scenes. You mention “increment that var by one” which maybe suggests you are using numbers as scene names which would make it as easy as putting lastSceneName + 1. However, I’m thinking this is not the case as the majority use actual names for their scenes.

I may approach it like this: Whatever means you are using to return to the last scene (you mention “animation plays and returns to the scene”), I am assuming a timeline action possibly, I would add some logic there that sets a variable to true and then run a check on scene load of the “last visited scene” (which could potentially be all scenes) and in this check (function) run a condition that checks for the variable’s state and goes to the next scene (visited scene plus one) if true by using the hypeDocument.showNextScene() method of Hype’s API.

Original code with variable added.

if (window.lastHypeSceneName == undefined)
{
// do nothing.
}
else{
window.seen = true;
hypeDocument.showSceneNamed(window.lastHypeSceneName, hypeDocument.kSceneTransitionCrossfade);
}

Code to run on scene load of last visited scene (potentially all scenes)

if(window.seen){
    window.seen = false;
    hypeDocument.showNextScene();
}

That’s my thinking.


(Stephen G) #3

Thanks for the lead! yes that makes perfect sense as my scenes are using names like S22-Q3-A, S22-Q3-B etc.

I will try to implement your suggestion,

Many thanks @DBear


#4

Just a heads up! The scene name will be returned as a string so it will take a lot more work to extract the number (22) in this case and add 1 and then re-assemble it. I would go the route I’ve suggested that deals with just the scene name references.


(Stephen G) #5

Excellent will do!


#6

Sry. Just realised a typo instead of

if (seen){...

it should be

if (window.seen){...

as I assigned it to window :wink:


(Stephen G) #7

[SOLVED] Cheers for pointing me in the right direction @DBear

When a correct answer is selected
window.keepCount = false;

onSceneLoad()
window.lastHypeSceneName = hypeDocument.currentSceneName();

if (window.keepCount === true){

hypeDocument.getElementById(‘showFeedback’).innerHTML = “VALUE IS TRUE”;
hypeDocument.showNextScene(hypeDocument.kSceneTransitionInstant, 1.1);

}

else if (window.keepCount === false){

hypeDocument.getElementById(‘showFeedback’).innerHTML = “VALUE IS FLASE”;

}

Then on animated scene
window.keepCount = true;

if (window.lastHypeSceneName == undefined)
{
// do nothing.
}
else{
hypeDocument.showSceneNamed(window.lastHypeSceneName, hypeDocument.kSceneTransitionCrossfade);
}