I have different objects in a scene and I want to control them with python code. My question is? Do I have to create a script for every object or I can control all of them with only one python script? I've tried with only one script but then there is only one object as the controller... and I need to change the properties of an object that is not the "controller". I don't know if I explained this well.
1 Answer
$\begingroup$
$\endgroup$
2
You can access all objects from the scene by its name:
import GameLogic
scene = GameLogic.getCurrentScene()
obj=scene.objects['ObjectName']
To access the vertices:
import GameLogic
scene = GameLogic.getCurrentScene()
obj=scene.objects['Cube']
mesh = obj.meshes[0]
for v in range(mesh.getVertexArrayLength(0)):
vert = mesh.getVertex(0, v)
print( "%d,%d,%d" % ( vert.x, vert.y, vert.z ))
print( dir( vert ))
-
$\begingroup$ Thanks! but I need to access to the vertex of the object and using scene = GameLogic.getCurrentScene() I can't do getVertex because is not defined $\endgroup$– AndreaCommented Jun 3, 2014 at 15:36
-
$\begingroup$ You should call
print( dir ( obj ))
to see what is available. Added access to vertices to the answer. $\endgroup$– stackerCommented Jun 3, 2014 at 15:58