Question on Script Synchronization

Post » Fri Jun 05, 2015 4:30 pm

For multiple global scripts that may operate on the same global variables, settings, objects or events, I am trying to understand if there is a best method to guarantee that global script A will always execute immediately before global script B in each frame. For example, if it's desired that script A detects an event (such as a sound starting/ending, stat change, etc) to possibly modify a global variable or setting before script B acts on the same event. Appreciate if anyone can confirm what works, what doesn't work and what may be considered best scripting practice among the following (or other) options:
#1: global start script A is higher in the same plugin start script list than global start script B
#2: global start script A is started by a different plugin earlier in the load order than global script B
#3: global start script A starts global script B on first pass before ending or returning
#4: global start script A starts global script B before end or return every frame, with global script B stopping itself before end or return every frame
Actually thinking about this more raises some bigger game mechanics synchronization question in my mind:
- within each frame is it clearly defined what order everything is processed in? For example, are PC actions and attached scripts always resolved before NPC actions and attached scripts followed by global scripts? Or is there some other order or is there no guaranteed order at all? (for single threaded engine, I'd guess there is some regular order but no idea what it might be)
- are scripts attached to the PC, actors or objects by another script (using xSetRef followed by StartScript) processed in the order of the script that originally attached them or in the order that PCs, actors and objects are processed? (I'd guess the latter but no real confidence about it)
User avatar
Tarka
 
Posts: 3430
Joined: Sun Jun 10, 2007 9:22 pm

Return to III - Morrowind