problem with overlay scene

hi all, i have a problem with overlay scene, if i add a scene and then i try to get it blender returns me a list index out of range error but in the game the scene is added, im using a code like this one:


import bge


hud=bge.logic.addScene("hud",1)


def prova(cont):
    
    sclist=bge.logic.getSceneList()    
    main=sclist[0]
    hud=sclist[1]

if i print sclist it returns me only the main scene and that’s why about the index error but why blender can’t find it if i can see the added scene in the game? how can i fix it?
thx

From the API regarding the addScene function:

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

i.e. You can’t access an added scene until the next logic tick after you’ve called addScene().

hum, so i have to set a delay of at least 1 tick for all the sensors having true pulse mode that need the hud scene?

edit:
i can’t figure out, sometimes i get error sometimes not without changing nothing in the code… this damned overlay scene its a pain

Do you think it is a good design that one scene knows about the other? What should happen when this other scene does not exist (anymore)? Wouldn’t it be nice to not care if the other scene exist or not?

When your logic relies on the existence of another scene, wouldn’t it make sense to revert the order of creation? This way you can be sure the scene is present already.

If you can’t do that, is it a good idea to apply an existence check each time you want to access the dependent scene?

my code has this line to make sure both scenes are loaded before allowing the player(which calls the HUD scene) to be spawned.


if len(logic.getSceneList()) >= 2:

have the module “prova” run when the player is spawned, and only spawn the player if the above code is True.