Modding existing LUA functions and their inclusion within mods

Barathor

Emperor
Joined
May 7, 2011
Messages
1,202
Basically, what is the best approach to modding some functions within AssignStartingPlots (or others)?

If I include a copy of the entire AssignStartingPlots within my mod and edit the code within it, it'll affect all maps generated; which I suppose is nice. But, then any other mod that also includeds AssignStartingPlots will break things.

Also, now I've just learned that any map scripts that replace functions within ASP (like Highlands) will also break the mod if you also included the entire ASP file in your mod. Is that correct, or did I misunderstand it?

The only safe alternative I know of is to create uniquely named map scripts that include the modified ASP functions (and other functions from other scripts). When I can, I try to just change variable values before calling the existing functions within the map script, but sometimes I have to replace the whole function.

So, I would need to select a number of different map types (Continents, Pangaea, etc.) and create unique versions of them. But, then that limits a player's choice of map when playing the mod. Yes, this is only a very minor issue.

So, other than that last method, are there any other options? I'm just curious.

------

Also, here's another question about LUA functions regarding project modularity:

I'll give a specific example so it's clearer.

I'm trying to make my project as modular as it can be so that each user with their unique tastes can play it as they wish. They'd do this by just either deleting, moving, or adding an affix to the name of the folder that contains the undesired code.

So, I have a folder that contains a modification to deserts and sets their base yield at 1 production (with other modifications to things related to deserts for balance). But, I also wanted to do it the right way, and I edited the fertility functions within AssignStartingPlots.

I know this wouldn't be a welcome change for some players, and they would want to disable the code within its folder. But, how do I go about enabling, disabling the fertility functions? Is there a way that I can create a unique LUA file that overrides the fertility functions within ASP?

As in, if a player uses this particular modification, the unique LUA file will override the existing functions within ASP with its modified ones. If a player disables this modification (using the folder method), then the mod will function normally and will just utilize the existing functions within ASP.
 
If I include a copy of the entire AssignStartingPlots within my mod and edit the code within it, it'll affect all maps generated; which I suppose is nice. But, then any other mod that also includeds AssignStartingPlots will break things.

Correct. This is the only way to do it, barring the map script method you'd described. And yes, this means that your mod will conflict with any mod that also modifies ASP. Modifying anything through the VFS is all-or-nothing like this.

Also, now I've just learned that any map scripts that replace functions within ASP (like Highlands) will also break the mod if you also included the entire ASP file in your mod. Is that correct, or did I misunderstand it?

That not quite right. Nearly all map scripts override parts of ASP, but it won't actually break anything unless you're changing something that would specifically cause them to conflict. For instance, adding a new strategic resource will break the Highlands, Lakes, and Great Plains map scripts because those three modify the resource quantity routines and the calling statement will no longer match the function declaration. But if you're just tweaking resource rarities or something, then no, modifying ASP won't break them. It might not give you quite the result you were expecting, but it won't BREAK.

But, how do I go about enabling, disabling the fertility functions?

Make them multiple mods, and let the player decide whether to use the fertility-modifying mod. But if you're trying to do this through modifying parts of ASP, then no, you can't cut and paste bits like that; it's all-or-nothing.
 
Thank you very much, Spatz, for taking the time to respond and explain this.

EDIT: I'll give that a try and tinker around. Thanks, Don.
 
Also, here's another question about LUA functions regarding project modularity:
It would not work for both your examples but in some cases you can declare new GameOptions to choose in the game setup screen. You can then use this option in lua to cut some features, like decide in assignStartingPlots whether you want to use the old fertility function or your custom one.
 
Back
Top Bottom