[answered] What is the execution order of scripts?

General discussion regarding the OpenMW project.
For technical support, please use the Support subforum.
Post Reply
User avatar
asmo
Posts: 229
Joined: 18 Sep 2014, 21:20

[answered] What is the execution order of scripts?

Post by asmo »

Hello,

is there a algorithm / rule which determines which script is executed first and when the other?

Right now I have a use case where script B shall only be executed when a condition is met in script A. It looks like that works when I'm accessing a status variable of script A at the very beginning of script B to check if the rest of B shall be executed.
However, that it works here doesn't mean that is works for other players.
So, is the execution order predictable? Maybe they are executed by name or by object type they are attached to. I remember that I read that all addons content is merged with the game data...

Thanks in advance!
Last edited by asmo on 14 Sep 2015, 17:51, edited 2 times in total.
User avatar
Zini
Posts: 5538
Joined: 06 Aug 2011, 15:16

Re: What is the execution order of scripts?

Post by Zini »

Within a frame local scripts are executed first, then the global scripts. There is no other guaranteed order beyond that. What ever order you are seeing beyond that may change at any time and you certainly should not write scripts that depend on it.
User avatar
asmo
Posts: 229
Joined: 18 Sep 2014, 21:20

Re: What is the execution order of scripts?

Post by asmo »

Zini wrote:Within a frame local scripts are executed first, then the global scripts. There is no other guaranteed order beyond that. What ever order you are seeing beyond that may change at any time and you certainly should not write scripts that depend on it.
I see - then this has to be arranged by accessing status variables of the other script.
Thanks :!:
wheybags
Posts: 207
Joined: 21 Dec 2012, 19:41

Re: [answered] What is the execution order of scripts?

Post by wheybags »

I hope there's not piles of mods that depend on some arbitrary sorting vanilla did ;_;
User avatar
asmo
Posts: 229
Joined: 18 Sep 2014, 21:20

Re: [answered] What is the execution order of scripts?

Post by asmo »

I'd like to know this as well:

script A contains

Code: Select all

 startscript B
Is B executed in the same frame where A came across that command or only in the next one?

Respectively script A contains

Code: Select all

PlaceAtPC my_NPC
and my_NPC has a script B. Is B executed in the same frame where my_NPC is placed or only in the next one?

Is both unpredictable or may the implementation change?
User avatar
Zini
Posts: 5538
Joined: 06 Aug 2011, 15:16

Re: [answered] What is the execution order of scripts?

Post by Zini »

Is B executed in the same frame where A came across that command or only in the next one?
Could be either way. You can not rely on a specific behaviour here.
and my_NPC has a script B. Is B executed in the same frame where my_NPC is placed or only in the next one?
Same.
User avatar
asmo
Posts: 229
Joined: 18 Sep 2014, 21:20

Re: [answered] What is the execution order of scripts?

Post by asmo »

OK, thanks
Post Reply