Creating Logic bricks from a python script

Sorry if this is asked before i checked the forum for a while but i could not found an answer. Is it possible to create logic bricks within a python script like

cube.actuators[“Move”] = GameTypes.KX_ObjectActuator()

this line is giving an error i know :slight_smile: but is there a way for this kind of use? or am i missing the point of logic bricks? Maybe logic bricks are not made for this kind of use?

you misunderstand what python and logic bricks are…
logic bricks are really just built python scripts that are readily usable… you can do the same thing with python that you can do with logic scripts… gamelogic isn’t editable in game… it is more a library…

hope that helps…

In other words:
There is an Python-API to the logic bricks. The API does not contain anything to create logic bricks while running the game.

Thanks alot for your answers guys. I am a newbie so i am trying to understand the consept of logic bricks and python scripting.

Logic bricks are an easy way to prototype functionality, but can get messy as it gets more complicated. There are things you can do with python that cannot be down with logic bricks (or can’t be done as easily). At very minimum, you need one logic brick to kick off a python script.You can use the sensors to trap a wide variety of event types, and those would be linked to a python controller where you can take action. You may or may not need an actuator in that action. You can have multiple sensors and multiple actuators connected to your python controller.

Regards,
John

Thanks a lot John your explanation is crystal clear so if I want to develop a game I have to use logic bricks at least for running my python scripts. I am a computer programmer so python way is much more for me don’t have any experience with 3d graphics, I want to keep learning curve as small as possible. I checked out crystal space but it looked harder to use on mac os x and if I hang on with that I was going to use blender at least for 3d graphics so blender looked much more like an all in one package to me.

You’re welcome!

I checked out crystal space but it looked harder to use on mac os x and if I hang on with that I was going to use blender at least for 3d graphics so blender looked much more like an all in one package to me.

That’s one of my favorite things about Blender (having it all integrated).

Hi okanbasoglu,

If you come from the programming, you might have some difficulties starting with Blender.
I suggest to think in objects. Each object can have its own set of logic.

The logic is always:

  • sensors triggering
  • controllers that activate/deactivate
  • actuators to make changes to actual game state

The execution ardoer is:

  • all sensors (of all objects)
  • all controllers that received a pulse from a sensor (controller with star activated run first)
  • all active actuators

The best is to think in a “parallel” way. There is no guaranty on the execution order of the objects.
Wihtin an object the logic bricks are executed up->down.

The Python controller is special, it is a controller, but can perform actuator tasks as well. That also means its tasks are performed before any actuator tasks.

Sensors are always verified.
Controllers are executed only when receiving an pulse from an sensor.
Actuators are executed as long as they are active. Some actuators deactivate after their execution (e.g. property actuator), others stay active until they get deactivated (e.g. motion actuator).

You can access a not connected sensor by a python script. You can even change this sensor’s configuration.
You can access a different controller by a python script. You can not trigger this controller.
You can access but not activate/deactivate a not connected actuator by a python script.

Why do I write this much, you haven’t asked?
Don’t know.

How do you do these last two?

I think it was something like this:

obj=getCurrentScene().objects['someObj']
firstObjController=obj.controllers[0]
someObjActuator=firstObjController.actuators['act']
changeSomeActuatorProperty=someObjActuator.frameStart="20"

But as Monster says you can not activate “someObjActuator”, because it is connected to an inactive controller(firstObjController) ,which you access from another controller of another object.

But you can use this method to set/get properties of different objs sensors/actuators…etc.
I use this widely in Krum to set ‘always’ sensors of different objects to usePosPusleMode=True/False it is very helpful.

That makes sense (the process for getting a reference to the actuator). It’s good to know you can get/set values. Thanks!

In fact there is an error in the last line:
changeSomeActuatorProperty=someObjActuator.frameStart=“20”

should be:
someObjActuator.frameStart=“20”

so after reading, i jsut need a confirmation! :stuck_out_tongue:

is there NO WAY of creating a:
an ALWAYS SENSOR
an AND CONTROLLER
and an IPO ACTUATOR

FROM a script? just by clicking stuff on the interface?

rica01: it is impossible at the moment, at least if you want to add them realtime. You might be able to make a program to add logic bricks for you outside of the game engine but I doubt you can do it with python.

thx pal! :slight_smile:

saved me a good time hehe:ba: