How to define forward compatible prototypes

Place to post guides, observations, things related to modding that are not mods themselves.
half a cat
Inserter
Inserter
Posts: 41
Joined: Sun Jul 16, 2023 4:03 pm
Contact:

How to define forward compatible prototypes

Post 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.
eugenekay
Filter Inserter
Filter Inserter
Posts: 503
Joined: Tue May 15, 2018 2:14 am
Contact:

Re: How to define forward compatible prototypes

Post 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!
robot256
Smart Inserter
Smart Inserter
Posts: 1199
Joined: Sun Mar 17, 2019 1:52 am
Contact:

Re: How to define forward compatible prototypes

Post 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.
Post Reply

Return to “Modding discussion”