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$
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$
  • $\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 Jun 3 '14 at 15:36
  • $\begingroup$ You should call print( dir ( obj )) to see what is available. Added access to vertices to the answer. $\endgroup$ – stacker Jun 3 '14 at 15:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.