Close all scenes

Lets say your in Scene A and you do Scene.push(Scene😎 and in Scene B you hit escape. How would you pop SceneA and B off the stack? 

In Scene B you can do Scene.pop() but that wont clear Scene A.

If this is not possible how do you reload Scene A after Scene B has been popped? Situation for this is that:

In Scene A, you have a selectable window, you scroll up and down and the right hand side window updates. This works because in scroll down and up I call TheWindowObject.refresh().

How ever it seems that once I hit enter to enter into Scene B and then escape to go back in to Scene A, scrolling up and down doesn't update the right hand side window any more. even though the refresh method is being called.

How do you pop all scenes when you pop one or How do you reload the scene you came from when you pop the one you are in 
When you call SceneManager's pop funciton, it will set the _scene variable to that of the last value in the scene stack. SceneManager also handles the main loo of the game, requesting that each time the browser window is refreshed, SceneManager's update function is called. In that update function, there is a function to check if the scene is changing, depending on whether or not there is a value to _nextScene, or _exiting is set, in which case the game is to close.

If the _nextScene variable is set, then the previously loaded scene's terminate function is called. On the next update, the new scene will be prepared and then updated until no longer needed.

If you want to clear multiple scenes from the stack, and you know specifically how many you wish to remove, you could directly access the stack with SceneManager._stack, and splice the number you wish to remove. Be sure not to leave the stack empty, though, or the nex time the stack gets popped, it'll crash since you can't create anything out of Null.
What happens if you do two return_scene commands in a row?


Or in Scene A, before calling Scene B, do a return_scene to get Scene A off the stack?
When you call SceneManager's pop funciton, it will set the _scene variable to that of the last value in the scene stack. SceneManager also handles the main loo of the game, requesting that each time the browser window is refreshed, SceneManager's update function is called. In that update function, there is a function to check if the scene is changing, depending on whether or not there is a value to _nextScene, or _exiting is set, in which case the game is to close.

If the _nextScene variable is set, then the previously loaded scene's terminate function is called. On the next update, the new scene will be prepared and then updated until no longer needed.

If you want to clear multiple scenes from the stack, and you know specifically how many you wish to remove, you could directly access the stack with SceneManager._stack, and splice the number you wish to remove. Be sure not to leave the stack empty, though, or the nex time the stack gets popped, it'll crash since you can't create anything out of Null.
this makes a lot of sense. thanks

@Zalerinian

Do you know if when I call this.pop() if the preceding scene does a refresh? or if that scenes object, such as windows, sprites or what not do a refresh? Because I don't want to kick you right out back to the menu if you go six scenes in  to something.
If you call pop, consecutively in each nested scene, they will each be rebuilt and updated. Scenes in the stack don't retain their data, the stack is just a list of classes that were called, so if you wanted to go backwards through each scene and do something with the data, you can't do that by default. However, if you just want to do something like dispose of sprites and other data, you'd alias the terminate function and put that in there. That will be called whenever the scene is changed, whether it be to go back a scene, or because a new one is pushed to the stack.
So how bad design would it be if you went Menu -> Scene A -> Scene B -> esc -> Menu ??
Well, there's always the idea that we should kinda just try to follow stand ways of doing things, but if you have a good reason and your plugin won't really work otherwise, I'd say do it. There are times when stepping outside that which is normal is necessary for us to do what we need. If you can't get it to work in another way, and you feel that the design is worth it, go for it. If we don't like it in the end, well whoops. People have opinions, not much you can do about that.
I fixed the issue

Original thread: https://forums.rpgmakerweb.com/threads/close-all-scenes.51175/