Blender <-> Python Execution Sequence

Ok, I’m a little “old school” an am use to compiling C++ programs which are sequential in nature. I’m trying to get my arms around which actions occur and in what sequence when dealing with logic bricks, scripts, and the game engine. I’ve been looking at trying to understand and duplicate the menu system that is posted here …

… but I can’t find where the program actually starts once the user hits the P-Key. How does Blender know which script to execute first? Is it based on the current displayed scene and the associated linked logic and scripts? If you have 2 objects with an ALWAYS sensor linked to 2 different scripts - which one executes first?

I’ve been through the file several times and understand the logic behind the fades, switching scenes, user selections, and the rest of the menu system … but I’m i’m a little confused as to which segment of code gets executed first … any insights? Thanks!


You can test this yourself, by creating a .blend with an always sensor, linking to script1, and script2. Put the following statement in script1: print “script1 ran”, and the following in script2: print “script2 ran”.

Set the always sensor to run once (turn off true level trigger pulsing), start game, stop game, look in the console for results.

IIRC, the controllers are executed from top to bottom.

As far as I know at loading time the BGE builds a list with all sensors, a list with all controllers and a list with all actuators.
When running all sensors in the list will be evaluated, then all controllers that get a pulse from their associated sensors and then all activated actutators.
The order depends on the position within this internal lists. As far as I know it depends on when an objects was added to the scene. For one object it is the visual order within the logic bricks as Social stated.

Since 2.49 controllers can be set to high priority to be on top of the list (the little start right of the controller bar).

The best option is to avoid dependencies between controllers and to avoid dependencies between actuators. For example one controller or actuator sets a property A to value 1 and another one overwrites the value with “X”.

If you do not have such dependencies you can think of a “parallel” architecture. Otherwise you get side effects as you can never guarantee the execution order. And the execution order might change with a newer release of Blender.

I hope it helps

Monster & Social - Appreciate the feedback and sorry for the delay - I’ve been doing a LOT of tutorials. I used some of the info you gave which helped clear up a lot questions. However, I DO need to start thinking Object Oriented and quit thinking Old School … :smiley:

… but I can’t find where the program actually starts once the user hits the P-Key

The basic answer to my original question is that the Scene displayed is executed when the user hits the P-Key. I was jumping around to different Scenes and couldn’t figure out why not all the logic worked after I entered the game mode. Reason: the Initialise script had not executed and loaded the .cfg file. DOH! :eek: Anyway, got it figured out now … it just took me a while.

On a side note, I had the hardest time figuring out how the background image was implemented. I kept trying to add a texture and then load a file for a texture which seemed the obvious way to put a picture into Blender. It wasn’t until I started digging around with the UV Mapping tutorials that I FINALLY figured out that the background was linked as a UV image and not as a texture. DOH! (x2) :spin:

Can either of you explain which would be better for mapping images (UV map or Texture) in the GE and why? And is there a way to spread a single texture across multiple faces (e.g. I’ve subdivided a plane several times, but have a single image that I want to cover the entire area). Again, appreciate the feedback …


I use Blender 2.45, a version before setting script priorities and I found that the last created object runs its script first. My setups have a logic empty with a startup script, so to ensure its always the first run I duplicate it then delete the original. You can then choose to send out an ‘update’ message from the startup script for extra assurance.