Can I assign a module to an empty or an object in my scene and when I run it to be able to define all the scenes, all their objects, all their sensors, their controllers and their actuators?
If yes, how? and if not, why?
thanks.
Edit: Also if I change the values of a variable in one script.Will another script run by different or the same object be able to read the changes?
Edit with the Answer!
import bge
import bpy
import sys
def initialization(name):
"""
The function "initialization" is responsible for:
1.Loading all scenes.
2.Setting all scene objects, object sensors and object actuators to variables with corresponding(where the dot "." is replaced with "_").
These variables are created into the function but are for global use.
3.The variable "cont" is created with its content being the controller.
"""
sys.modules[name].cont = bge.logic.getCurrentController()
for s in bpy.data.scenes.keys():
bge.logic.addScene(s)
for scene in bge.logic.getSceneList():
for obj in scene.objects:
exec("sys.modules[\"%s\"].%s=scene.objects[\"%s\"]"%(name,str(obj).replace(".","_"),obj))
for sensor in obj.sensors:
exec("sys.modules[\"%s\"].%s_%s= obj.sensors[\"%s\"]"%(name,str(obj).replace(".","_"),str(sensor).replace(".","_"),sensor))
for act in sys.modules[name].cont.actuators:
exec("sys.modules[\"%s\"].%s=sys.modules[\"%s\"].cont.actuators[\"%s\"]"%(name,str(act).replace(".","_"),name,act))
So,this is a module(with the name “Initialization.py” that I have saved in the same folder with the other modules I use and the .blend file. At the start of each module I want to use I just write this:
import bge
from initialization import initialization
initialization(__name__)
Now every sensor,object,etc. that I mentioned above can be retrieved and used