views:

168

answers:

1

I would like to let my initializing script to create additional sensors/controller/actuators necessary for an interactive Blender application (not necessarily a game). This is preferable for two reasons:

  • I can use this script in multiple applications. Creating common logic over and over again is tedious. And there is no other way to import AFAIK.
  • Having my Python modules create logic bricks is much easier and comfortable for me since I'm a coder. (...and the code can be version controlled, peer reviewed, easily documented etc.)

Actually creating a template file partially addresses the first issue. But then I can't mix and match different parts for different projects, or I have to create a template for each possibility.

I have searched both the Game Engine docs and the Python API but couldn't find any clue. __init__ methods of logic bricks aren't even listed there.

But if there is any way to create logic bricks dynamically within Python I would like to try it.

NOTE: with my limited knowledge of BGE, you can't, for instance, access key presses directly from Python. A sensor is required.

+1  A: 

So -- as it is, there is no way to create the logic bricks straight from Python.

When you instantiate an object in ther BGE (like with an add object actuator), the logic bricks from the instantiated object comes with it - and you can change and rearrange those - including the rewiring of the sensors, controler and actuators

I think this is the current workaround: you create a blank matrix of generic senor, controlers and actuators, and as you add new objects into a scene, call a function that fill-in the parameters for the logic blocks and do the required wiring.

jsbueno
Thanks for the answer. But I'm not sure I understand the method you mentioned. Can give a more concrete example?
muhuk