how to replace specific scene with python?

how to replace specific scene with python?
something like:

scene=(“Scene01”)
if sensor.positive:
scene.replace(“Scene02”)

for scene in bge.logic.getSceneList():
     if scene.name =='targetName':
          #replace scene here

use replace scene https://docs.blender.org/api/2.78a/bge.types.KX_Scene.html#bge.types.KX_Scene.replace

  • the replacement function seems to be missing, but it does this:
import bge

cont = bge.logic.getCurrentController()
own = cont.owner
scene = bge.logic.getCurrentScene()
scenes = bge.logic.getSceneList()

sens = cont.sensors['mySensor']

if sens.positive:
    scene.end()
    scenes = bge.logic.addScene("02-scene", 0)

example - scene_replace.blend (443 KB)

:wink:

if it’s the current scene to replace it’s like this:


import bge


scene = bge.logic.getCurrentScene()


cont = bge.logic.getCurrentController()


own = cont.owner


sens = cont.sensors['mySensor']


if sens.positive:
    scene.replace("Scene02")

but i need to replace specific scene not the current scene, because i have a overlay scene (HUD) i’m trying using python with Sensor and Controller in HUD scene to replace scene01 with scene02

so it’s like this:


import bge


scene = bge.logic.getCurrentScene()


cont = bge.logic.getCurrentController()


own = cont.owner


for scene in bge.logic.getSceneList():
     if scene.name =='Scene01':
         scene.replace("Scene02")

thanks for your help guys

import bge

cont = bge.logic.getCurrentController()
own = cont.owner
scenes = bge.logic.getSceneList()

sens = cont.sensors['mySensor']

if sens.positive:
    scenes = bge.logic.addScene("02-scene", 1)
  • delete - scene = bge.logic.getCurrentScene() and scene.end() - do not need anymore
    and change to 1 (this overlay) - scenes = bge.logic.addScene(“02-scene”, 1)

thank you for the useful tips

  • So no problem! Do not forget - SOLVED, please :wink: