Resume current paused scene.

Hi.
In a lot of bge tutorials that explain how to make a pause menu there is 1 scene + 1 pause menu scene.
When you press Esc. the scene will be suspended and the pause menu scene will be added as overlay scene. If you press Esc again the sensor in the pause menu scene will activate a actuator that will resume the ‘game’ scene and a actuator that will remove the pause menu scene.

But what if you have 20 different stages/scenes in your game. How to tell the actuator in the pause menu he must resume that current paused scene? I don’t want to make for every single stage one pause menu, but just 1 pause menu for all stages/scenes. I tried to do this with python but I’m a beginner with python and it didn’t work as I expected. I can’t share the python script I made because it was one big mess that didn’t work so I deleted the whole script :eyebrowlift2:.
I hope I was clear enough, I hope you can help me.
Thanks :smiley:

Ow, shit I posted In the wrong sub-forum. Can someone move this to bge support and discussion?

Due to the dynamic nature of your request you need a Python controller to setup a scene actuator with the scene to be resumed.

This is pretty simple via KX_SceneActuator.scene = sceneName (don’t forget to activate the actuator too).

The problem might come up to determine the name of the scene to be resumed.

This is up to you as you suspended it ;). (some options: it is the only other scene, you send a message with the scene name when suspending it…)

ok. thanks. So how to set a property of a object in another scene? So I can set a property in the pause menu to the scene name.

I would not do that at all. One scene would need to know the internals of the other scene. It is possible, but creates unnecessary dependencies.

Find Level scene:


scene = findSceneByPrefix("Level_")

...
def findSceneByPrefix(prefix):
    for scene in bge.logic.getSceneList():
        if scene.name.startswith(prefix):
            return scene

Assuming there is only one active (but maybe suspended) scene with “Level_” prefix.

Telling the scene name before suspending itself:


scene = bge.logic.getCurrentScene()
bge.logic.sendMessage("suspending scene", scene.name)

This sends the scene’s name via message. You should execute this code at the same frame when you activate the suspending.
The Menu scene can store the scene name:


def firstBodyToScene():
    messageSensor = ...
    resumeActuator = ...
    sceneName = messageSensor.bodies[0]
    resumeActuator = sceneName

Do not actuate it at that time, it just sets up the scene name in the actuator. You activate the actuator later when you want to resume the level just with an AND or OR Controller.

Sensor “request resume” -> AND -> activate Resume Scene (which is already configured at that time)