BGE python run order.

Hey.

I have two scrips, char_move.py and mouse.py. Its a third person game and the mouse moves the cam and the keyboard moves the char, depending on the angle of the camera.

The rotation of the character is jittery when I rotate the camera while move the character. This is because in the game loop the character is moved, therefore his rotation is set, before the camera movement is set.

My question is how do I make one python script work before the other without coding a whole new script, if possible?

You should design your controllers that they do not rely on the order they are executed. There is simply no guaranty what the final order will be.

While this is a golden rule there are some rare exceptions. E.g. you want to ensure a Python controller gets executed before any other e.g. to perform a global initialization (e.g. to print the current frame number to console before any other code prints any output).

To do that you can enable the priority flag. Really, this is for the exceptions only.

There are still other exceptions. The controllers within a single object are executed in the order they appear in the GUI (top-down). You can use this side-effect to execute a sequence of controllers within a single frame. e.g. one does some initialization the next one assumes they are already done. Nevertheless, it is a better design to initialize right before accessing the according data.

General hint: if you think you depend on the execution order, check if you chose the right design.

Controllers should execute in the order they are placed in the stack of bricks, controllers near the top are executed before the ones further down.

There’s also a flag as Monster said that allows you to force certain controllers to fire first, no matter where they are in the stack.

Then there’s the idea of making a controller wait until an actuator is activated, which is what you can reportedly do with the actuator sensor (yes, it’s in the sensor list).

With these three things in mind, it shouldn’t be too difficult to avoid timing issues.