Logic Bricks Question

I get that logic bricks are implemented in C and are more efficient than python. Is is possible to instantiate logic bricks in python? I’m finding the gui interface a bit unwieldy and would like to create all the logic bricks in an init python script. Am I correct that the only way to setup a logic brick is with the gui?

You mean you want to use a Python code to set up your logic bricks at the beginning of the game? I doubt that you can do that. I’ve never heard of it being done before, and it doesn’t sound very practical. If you wanted you could look into it by mapping out the dir() listings for the GameLogic module. Run the code

print dir(GameLogic)

then run it again on your results (results print to console). There might be some tool somewhere in the module to do what you’re asking. Even if you do find a way you will obviously need to set up two logic bricks in the GUI: “Always (true pulse turned off) --> Python: YourInitScript

I get that logic bricks are implemented in C and are more efficient than python. Is is possible to instantiate logic bricks in python? I’m finding the gui interface a bit unwieldy and would like to create all the logic bricks in an init python script. Am I correct that the only way to setup a logic brick is with the gui?]

You can keep the number down by leaving most of the information blank. Some of the sensor information doesn’t fill in, though. It’s a style that you get used to. I lke it myself. The 3d view is like an editor, really. You click on an object to bring up it’s code. A 3d object outline.

You can just use Ogre if your into that type of thing. There’s even a PyOgre if you prefer python. It’s something like wanting visual basic without the forms. If you don’t want the forms, you no longer need visual basic.

I can live with an initial logic brick to trigger the python script.

Basically, I have my game mapped out, objects named and described, game element behavior defined and storyboards. I don’t mean in Blender. I’ve done this as a text and sketch description of the game. Since I have the extent of my objects defined in a control doc I would like to define the behaviors and relationships in on place and in script form. That way, if later during testing I need change anything, it’s all in one place.

Let’s say I have three checkpoints in the first level. At the second checkpoint, known by using near sensor, I want to create a radar sensor and when the actor moves away from the checkpoint, destroy the radar sensor. I want to do the dynamically ‘on the fly’ while the game is running rather than define the radar sensor and ‘AND’ it with near sensor during game development.

Reviewing the logic brick documentation I can see how to use the functions of a logic brick, but not how to instantiate it and link it to an object while the game is running.

I don’t think it’s possible either but not finding any examples or documentation specifically stating one way or the other I thought I would ask here.

Thanks for the help, Steve

Why not set a boolean property on the radar called “Active”, set a logic AND to check the property as well as the collision and an action to change the property to false when triggered?

You can’t add or remove sensors/controllers/actuators on the fly.
Here some ideas what you could do:

  • you could remove a complete object to remove the logic.
  • increase the frequency {setFrequency(freq)} of a sensor to a real big number. If you need the sensor (e.g.ray) just set it back to 0. (I’m not sure if this provides a speed improvement.)

Maybe there are more ideas.