When I’m writing scripts for games, I use module scripts (script.py) with defined functions inside. At the top of the script, not in a defined space, I have this code:
from bge import logic sce = logic.getCurrentScene() sl = logic.getSceneList() def firstFunction(): object = sce.objects['name'] #etc...
I’m not sure if this is a very “morally acceptable” way of starting a script, so please let me know if there’s a more efficient way of getting these important variables instead of typing them at the start of each function.
The problem is that when I remove an overlayed scene with “scene.end()” and re-add it with “l.addScene(‘name’)”, I receive this error multiple times when the newly overlayed scene runs its script which tries to access those variables defined at the header of the script:
SystemError: value = CList[i], Blender Game Engine data has been freed, cannot use this python variable
What I suspect is happening is the variables defined at the top of the script have been cleared from memory and aren’t being redefined when the script runs again once the scene has been re-added. I run these functions by Module controller block rather than Script.
So why is it that these variables are recognized the first time the scene is overlayed and the script run, but not the second time the scene is overlayed? Is there any way to get around this, or is there something I’m missing here?
Any info would be of use, I’m currently having to move the position of the overlayed scene’s camera far away from the center of attention to make it look like the scene isn’t there.