I am getting a list error, that the scene I am trying to access does not exist(CList[key]: key not in list)…we’ve all seen(no pun intended) it before and it is usually something simple…but I cannot figure out why I am fighting with this…I even went so far as to copy and pase code I had that worked before, rewriting the script from scratch I still get the error…
I am thinking maybe something I am doing is just a simple mistake
it takes 1 frame to add the scene, so everytime i start my game i have 5 messages that there is no scene “Overlay”, but the next frame its there and the error gone
(solution i have for this is that i have a start scene, which adds the overlay scene and the normal scene and deletes itself, so the overlay and the normal scene are both simultaneously added and there is no error )
# to grab an object, get_object('scene_name','object')
# to grab a scene, get_scene('scene_name')
def get_scene(scene_name):
scenes = logic.getSceneList()
scene = None
for sce in scenes:
if sce.name == scene_name:
scene = sce
if scene == None:
print('
*** No scene found with the name: ' + str(scene_name) + ' ***
')
else:
return scene
def get_object(scene_name, object_name):
scene = get_scene(scene_name)
object = scene.objects[object_name]
return object
make sure the scenes are running.
The above code will check if the scene exists and if so it will return it.
thanks again cotaks, I did get it…I basically just let it ‘wait()’ until the game recognizes the scene…it was as Leralasss stated…it took a frame to load it.
It is (as mentioned above) a question of timing. The scene list is - the list of the currently loaded scenes. At game start only the start-up scene (the current one) is loaded. Therefore you can’t find the other scene.
This means you better run that code when the requested scene is loaded too. Which is earliest the frame after loading the requested scene.