I want to define the same prototype in two independent mods such that there will be minimal problems if the prototype changes in the future. What is the recommended practice to do that?
Some mods construct the final lua table for a prototype before inserting it into data. Other mods insert a minimal table into data and then modify the table. It seems to me like these designs stem from different decisions about how to make code that is compatible with future changes.
How to define forward compatible prototypes
-
- Inserter
- Posts: 41
- Joined: Sun Jul 16, 2023 4:03 pm
- Contact:
Re: How to define forward compatible prototypes
Do you want to end up with “Two different Prototypes”, which don’t interact but look very similar? Just split it out into a separate Lua file in your Source, and Include/Require it in both Mods at build time.half a cat wrote: Wed Mar 19, 2025 2:47 am I want to define the same prototype in two independent mods such that there will be minimal problems if the prototype changes in the future. What is the recommended practice to do that?
Some mods construct the final lua table for a prototype before inserting it into data. Other mods insert a minimal table into data and then modify the table. It seems to me like these designs stem from different decisions about how to make code that is compatible with future changes.
Or “One Prototype defined by two different mods”? Define it in Both; but add an Optional Dependency between them and IF() statements to only conditionally load one of them.
Good Luck!
Re: How to define forward compatible prototypes
If you want to make sure it's the same prototype no matter which mod (or both) is loaded and which was updated most recently, you can make a library mod that both mods use as a dependency.
My mods: Multiple Unit Train Control, Smart Artillery Wagons
Maintainer of Vehicle Wagon 2, Cargo Ships, Honk
Maintainer of Vehicle Wagon 2, Cargo Ships, Honk