I need to be able to switch scenes in python code while in game, and I don't mean hooking up a python controller to a scene changing actuator, I need to be able to change scenes without it. Does anyone know how it would be done?
It does exist in the API, the trick is you have to get the scene first:
for scene in bge.logic.getSceneList(): if scene.name == 'oldSceneName': scene.replace('newSceneName') break
Another useful 'replace scene' like thing that I have done quite a lot is to end the current scene(s) and then add the new one:
for scene in bge.logic.getSceneList(): scene.end() bge.logic.addScene('sceneNameGoesHere')
The BGE API (version 2.77) does not support to switch scenes without an actuator.
The scene actuator is sufficient enough.
- You will never be able to switch to more than one scene. [dynamic number of switches]
- You already can dynamically setup the scene to switch to. [dynamic calculation of the target scene]
- A scene switch will always performed AFTER the current frame (after the actuators where processed). [timing]
You can dynamically add overlay/background scenes via addScene(). This is to add several scenes within a single frame without the need to know the number of scenes beforehand. (Otherwise you need n actuators for n scenes to add).