Logic cycles with Python modules

I am creating a little game and for now I have 3 scenes and 2 python modules:

  • MenuScene

  • GameScene1

  • GameScene2

  • Menu.py

  • Game.py

MenuScene must display a menu and the GameScene must be loaded when pressing a START button. For now it only contains a camera, with an ‘Always’ sensor and a Python module (Menu.py) function (Menu.start) as a controller.

The Menu.py module imports the Game.py module, which is a common module that must be able to load/unload any scene of the game. It can load any of the game scenes but it also must load the menu scene if I exit the game to the main menu.
So, for now I must make sure Game.py know all the scenes of the game and here is where I have a problem.
This is my initial code in Menu.py:


import bpy
import Game

# start function
def start():
    # load game
    Game.load()

and my Game.py module:


import bge

def load():
    print("Loading game...")

    scenes = bge.logic.getSceneList()

I expect scenes to contain all 3 scenes but it only contains the actual one. Of course, I checked the API reference and saw this:

Note
Scenes in your blend file that have not been converted wont be in this list. This list will only contain scenes such as overlays scenes.

I don’t understand how I must convert the scenes or what does this mean so I tried to add the scenes with bge.logic.addScene before getting the list but it doesn’t work and I suppose the cause is, as explained in this other note:

Note
This function is not effective immediately, the scene is queued and added on the next logic cycle where it will be available from getSceneList

Now, how do I detect or force the next logic cycle so I can get the added scene? Or, maybe there’s another way of getting all the scenes. I am using modules and it seems like the Menu.start function assigned to the ‘Always’ sensor is only executed once. Maybe someone can tell me how would I do this while I am digging for more functions/sensors/actuators in the API reference that could help me.
Thanks for your answers

Side note: Wouldn’t it be better named Loader or so?

Unfortunately there is no explicit way of telling what Blender scenes are available in a .blend file (or Memory).
A good work-around is to use naming conventions (e.g. scene.001 …scene.999).
Another way is to use configuration e.g. a list of scene names created by you.

I assume you did not enabled True Pulse mode.

Have a look at http://gameblender.wikia.com/wiki/Sensors for more details.

You should use


scene = bge.logic.getCurrentScene()
scene.replace("name")

to change scene based on scene name alone.

BGE API

Thanks, @Monster. Indeed, I True Pulse was not enabled