Page 1 of 1
How to define forward compatible prototypes
Posted: Wed Mar 19, 2025 2:47 am
by half a cat
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.
Re: How to define forward compatible prototypes
Posted: Wed Mar 19, 2025 4:18 pm
by eugenekay
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.
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.
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
Posted: Wed Mar 19, 2025 5:30 pm
by robot256
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.