I've found a way to define my scenes correctly as some scenes are inactive at the very start of the game engine and cannot be found. However, since the code can't find the scene at the very start, it prints an error only once. On the next run of the script, no errors are printed as the scene is found. Is there a way I can have a script re-execute a block of code until the desired outcome comes? In other words, keep redoing the function (find scene), and keep re-executing itself without continuing with the rest of the script and only continue once the scene is found? And is there a way I can have the console not print the error using this idea?
I'm not sure what exactly you are expecting.
The BGE loads and starts with exactly one scene (the current scene in Blender). It simply has no other scenes.
To add other scenes (Background or overlay) you either use the Scene Actuator or the BGE API. (I guess you know that already).
This operation will be performed after the current frame. In your case between frame 1 and frame 2.
Therefore you will never be able to find any other scene at frame 1. They are simply not loaded yet.
They are loaded within the next frame. In your situation in frame 2.
There are several options to deal with that situation:
Each scene performs operations on currently existing scenes after being loaded.
The current scene is always the new one. Make sure not to look for other scenes, that do not exist yet.
Check for a scene after is was loaded
You know when you added the scene, check within the next frame.
The current scene is the scene that added the other. The new scene is a different one.
Send a message notifying that the scenes changed.
This way any object that is interested (regardless in what scene it resides) will be notified and can act accordingly.
The scene the listener is living in can be, but does not need to be the new scene.
There can be any number of listeners.
I hope it helps
Edit: now I see it is related to question 44362. I think the above suggestions should help you with your problem (which is a strong dependency from one scene to the other [not really a good design as you see])