using python

Hey, I’m kinda new to blender game engine. I know javascript and php, so I would rather use something text based with more flexibility, and I know that you can use python instead of logic blocks, but I don’t know how. I’ve tried to find out exactly how, but it’s hard to find much, so I figured someone here would be able to help. So could someone please link me to a good site for this?

Thanks!

You can’t use Python instead of logic blocks.

The python controller is a logic block. And that is the place where you can setup your Python code. (you still need place the code in a text file with any text editor :wink: )

The Python controller works like all the other controllers.
With one exception:

  • it can perform tasks that actuators should do (therefore there is no Python actuator)

So read on how sensors, controllers and actuators do and how they do it. I think you find some good information at Blender.org.

Short description:
2 Modes:
Script mode

  • when a sensor triggers the controller it interpretes and executes the textfile with the name you entered in the Script field

Module mode

  • when a sensor triggers the controller
  • the first execution: it loads and initializes the module which name is entered at the Module field (can by an external .py file)
  • each execution: calls the function that you entered after the module name in the Module field (separated by a ‘.’)
  • you define the function in you module.
  • the function gets one argument: the current controller executing the function
  • the module remains in memory after executing the controller

I hope it helps