SeneChange() mystery in JavaScript

Hey All!
I have ran into another mystery in my quest to learn GDJS!
I have a timer to restart my game after some animations finish.
I want to first send the player to a quick hi score scene.
Here’s a code excerpt:

if( TM.getTimer( "TM_RESTART_GAME" ).getTime() >= 2500 ) {
    runtimeScene.requestChange( gdjs.SceneChangeRequest.PUSH_SCENE, "HiScore" );
    runtimeScene.requestChange( gdjs.SceneChangeRequest.STOP_GAME, "HiScore" );
    gdjs.evtTools.runtimeScene.pushScene(runtimeScene, "HiScore");
    console.log( "Restarting");
    runtimeScene.requestChange( gdjs.SceneChangeRequest.REPLACE_SCENE, "Level 1" );

As you can see, I check to see if Timer is expired, then I have 3
slightly different attempts to change to my “HiScore” scene and they all fail. “Restarting” is sent to the console and the ChangeRequest() for level 1 triggers and the game resets (as expected).
The “HiScore” scene just won’t fire in this if block. If I place (any) one of the “HiScore” scene change lines just above the if, it will work.

I don’t know what it is about having this request inside an if block, but that seems to be the problem!

Can anyone shed any light on this strange behavior?
Thanks!

The question is a bit hard to understand, can you make it more clearer?

I’m guessing you want timers to be globally persistent?

Hey, @planktonfun !

No, my issue isn’t with the timer at all. It’s just how my code flows - the player is killed and starts to drop. This timer is then set to end the game after he falls for a bit.
It’s what I’m doing in the timer. I want to pause and change to my hiscore scene and then return. As mentioned, the three desperate lines I have to accomplish this are mysteriously ignored (the first 3 lines in the if block). I know I don’t need to pause and return in this way, but It’s supposed to be possible and as someone learning the engine, I don’t feel great when something is advertised to work and I can’t get it to work for me. I feel like I’m still missing a piece of the big picture!
In fact, I have moved on with another method, but this mystery still bothers me.

I’d sure love to know more about this, If anyone can help.

As far as I know all events (including JS events) are scene specific. You’re running a JS event in one scene, it’s not going to continue after you switch to another scene.

Edit: More specifically, the entire event is processed, so it’s going to switch to the last valid thing it can see, which is likely your last scene change call. Even if it did change to one of the prior scene changes, it would not process the whole event, since you’ve changed scenes.

Hey! Yes, I was counting on that being the case. That makes sense to me.

it would not process the whole event, since you’ve changed scenes.

Welp, see, here’s the thing, kinda two things:
I’m requesting the scene change as “PUSH_SCENE”, which is documented as pausing current scene and starting another, then pop back. And as I mentioned in my original post, it will do that if I place the request just above the if block - it’ll take me to the HiScore scene and come back.
What’s troubling me is that it gets completely ignored in the if block like the code in my O.P. As you can see, as an act of desperation, I have done it several ways and one of the lines is actually a “STOP_GAME” - which gets ignored too.
All I get from the code is “Restarting” in the console and it will run the “RELPACE_SCENE” for “Level 1” - which is the current level.

Umm. so that’s what I’m spooked out about. The code is flowing like I expect it too, it’s just totally ignoring my PUSH_SCENE’s - - but only in the if block - it will push and return outside the if block.
(PUSH_SCENE Documentation is here.)

OFC, I’ve since went ahead and done a single REPLACE_SCENE for my HiScore and life is good again. It just sucks because I’m getting on so well with the engine and I’m building trust with it, but this little thing has me spooked.
I gotta assume as I learn more and more, one day I’ll figure out why, but for now it remains a mystery! I’ve traced the code around with a debugger, but my eyes just gloss over and I have no idea what I’m looking at yet, LOL.

Thanks all for your input!

If that’s your goal then you can do this with events

Game scene events:

HiScore scene events:

This will pause the game, display the leader board for 2.5 seconds and resume the game.

Cool! Thanks. Yeah …I had the scene “pause and start” working in both events and java script. I also have the leader board working as I want in java script, so I’m not stuck.

Again, it’s the fact that the working line of javascript code to pause and start a new scene does not fire inside my if block. That’s my mystery!

But I do appreciate all the input I can get. Thanks!