5
$\begingroup$

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.

$\endgroup$

1 Answer 1

4
$\begingroup$

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 ))
$\endgroup$
2
  • $\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$
    – Andrea
    Commented 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$
    – stacker
    Commented Jun 3, 2014 at 15:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .