Best way to remove all game scenes?

Hi,

What is the best way to end all active scenes and then move on to another scene?

For example, end main game scene and all overlay scenes, and then go to main menu. I want the scenes to just be killed completely and want them reset when the player goes back.

The method I’m using at the moment is a bit rough.

I first get a handle to the main game scene, so that I can use scene.replace()


scene_game = logic.getSceneList()[0]
scene_game.replace('Main_Menu')
for i in logic.getSceneList(): #End all game scenes HUD etc
    i.end()

It’s probably worth noting that the code is being run from one of the game overlay scenes and not the main scene itself.

It does seem to work, but I can’t help but think it’s not right.

Scene actuator - set scene, it ends the active scenes for you and starts a new one.

Hey hreidmarr, thank you for the feedback but I’m afraid that’s not quite what I’m after. I want to iterate through ALL scenes (which in my example includes a couple of overlay scenes) and end them all, and then move on to another scene.

Maybe, is there a way to switch to another scene without having a handle to a current scene? So I can iterate through all scenes and end them, and then just do like…logic.scene = … instead of currentScene.replace()…or something along those lines?

The problem I’m having is, I have to have an active scene to call scene.replace(), but if I have deleted them all then I can’t do that.

You could set up each scene to close themselves when a particular message is sent.

Hey Terra,

I was thinking to use something with messages.

Maybe I could have a single short script that gets the current scene and ends it, that is run when a message is received. I already have controller empties in each scene so I could set those up to receive the message and run the script each.

I’ll give that a try later.

Sounds good. :3

Uh-oh, I didn’t think about the changing scenes after. Is there a way to set the scene, when all current scenes have been ended?

Hmm… You could make it so that when the new scene is started it sends the kill command to the rest of the scenes. Either that, or you do this all from a python script and have the start command go right after the kill command. It should finish the script before BGE closes itself.

Simply send a “kill” message to all. One can set the next scene and kills itself too.