Script execution precedence
Script callback functions are not executed in a random order: script location and type have an influence on when (in relation to others) a script is executed or called:
Execution precedence is first and foremost based on location: a child object's script has always higher priority than its parent's script, and thus will be called before. In case of two sibling objects, precedence is given by the order they appear in the scene hierarchy, unless they have a different priority flag, in which case that flag decides the precedence. See the script dialog for details.
Execution precedence is next decided by the script type, from first to last executed: child script,customization script, add-on script, and finally the sandbox script.
[Example scene with script execution precedence]
A simple rule to remember is: the more important or persistent a script is, the later it will be called. There are exceptions to this, depending on the callback type: e.g. the contact- and the dynamics callback are executed in reverse order. Additionally, when the caller expects a return value, the call chain is interrupted as soon as the first return value is received.