Sign in to follow this  
Ultroman

Mod Load Order Priority

Recommended Posts

Ultroman    735

In modinfo.lua we have a variable called "priority", and the higher this value is (compared to other mods) the earlier it will be loaded, and thus the lower it is, the later it will be loaded. So, a mod load order could look like this.

Priority 300 - Mod 1
Priority 300 - Mod 2
Priority 1 - Mod 3
Priority 0 - Mod 4
Priority -1 - Mod 5
Priority -3 - Mod 6

If that's correct, then I'm happy so far :)

Now, how does that impact the modutil functions? If I have a mod where the only functionality is to call AddComponentPostinit() or AddPrefabPostinit() or AddPlayerPostinit(), does the load order matter? My guess would be no, thinking that all these postinits being compiled into a list, and then after all the mods are loaded, the world starts generating and applying all the postinits as it spawns entities. If so, then the "priority" variable is irrelevant for my mod, right?

Also, what are the maximum and minimum values acceptable for the "priority" variable? I always wanted to know, and I can't find that info anywhere.

Share this post


Link to post
Share on other sites
YakumoYukari    150

Your assumption of the load order is correct. Higher priority loads earlier.
Every mod is zero priority given by default. If same, it will load in lexicographical order.
 

And, yes. It affects modutil functions. It would be helpful if you look at the code in modutil. Especially InsertPostInitFunctions.
Every PostInit functions are inserted by table.insert() into an environment table, named postinitfns. 
It is executed in runtime, including the main loads(for the client mods mostly), worldgen and the world loading. 
Since every element in the game environment(prefabs, stategraphs, actions...) is being variable and separated, it has its own time to appear. And if any post functions exist on that element, the function runs, in the load order.
And I do believe that all workshop mods are written in lua which doesn't compile. But executes everything in runtime, line by line.

The only matter on the load priority is, how to use it. 
If you made a prefab post init function that overrides everything about inst, for example, will lose most load order data applied previously.
In this case, you need to set your mod priority to the lowest, -2147483648 and rename your mod name start with.. something beyond the 'z' in lexicographical order of the lua sorting algorithm in order to fully apply your code.
To avoid this, you can always think about the other mods and use various skills like chain-function.
It is always the best to make your mod not to inflict with mods made by other people.


Also, you can freely assume the data range of the integer of Lua 5.2 is the int32's.

Edited by YakumoYukari
  • Like 1

Share this post


Link to post
Share on other sites
Ultroman    735

Thanks a lot, YakumoYukari! I knew I could count on one of you madlads to know all about this stuff, so thanks a bunch for that write-up <3 I'm sure many other people will be helped by this information in the future, as well.

Luckily, the mod I was concerned about doesn't really care when its code is processed, given what you've stated here, but I'll look at my other mods to see if a change might be needed.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this