Mod configuration file best practices?

AeonsOfTime

Chieftain
Joined
Mar 4, 2017
Messages
10
Hi all, I have a small mod with some configuration settings in a lua script. I would like to move these configuration settings to a separate file, so they can be easily edited without opening the main script. It can be another lua file, an xml file, or whatever other format that can be used.

For the last two days I have tried finding examples, and looked at a bunch of modding guides, but was unable to find this particular topic. I would love to hear how you go about it (I assume it is possible), and what you think would be the best practices to do this.

The specificities of my project:

- The lua script has its default settings, the configuration file should be used only if it exists.
- It has to be a file, so players can easily modify the file.

I'd appreciate any help!

Cheers,

Aeon.
 
We can also include the contents of one lua file within another.

So you can set your variable "configuration" data for the main script in a short lua file, and then have the main lua script "read-in" the contents of the short lua file.

Just beware that whenever a mod is updated by you, that update will make the custom data-settings an individual user has made go poof
 
We can also include the contents of one lua file within another.

So you can set your variable "configuration" data for the main script in a short lua file, and then have the main lua script "read-in" the contents of the short lua file.

Just beware that whenever a mod is updated by you, that update will make the custom data-settings an individual user has made go poof

Hi LeeS,

my idea to circumvent the update side-effect was to let the user create the config file, so it is not updated when the mod is updated - then I found out yesterday that when a mod is updated, the existing mod folder is actually deleted, then re-created, so that would not work either.

Would you show me a snippet on how to read in the contents of a lua file? I only remember reading that it's not possible to include one - unless that changed since then.
 
The inability to include was cured many moons of patches ago.

Code:
include("LeeS_PlotToolkitRoutines.lua")
This will add the entire contents of the file called "LeeS_PlotToolkitRoutines.lua" at that point in the file where the command appears. The text within the file "LeeS_PlotToolkitRoutines.lua" is grabbed and copied into the other lua file, but if two or more lua files are both/all including the same file, this does not allow dynamic data passing between these files.

LeeS_PlotToolkitRoutines.lua:
Code:
Cheeseburgers = true
1st "Main" lua file
Code:
include("LeeS_PlotToolkitRoutines.lua")
if (Cheeseburgers == true) then
   print("Cheeseburgers is true")
   Cheeseburgers = false
else
   print("Sorry, No Cheeseburgers")
end
2nd "Main" lua file
Code:
include("LeeS_PlotToolkitRoutines.lua")
print(Cheeseburgers)
In both cases a value of boolean true is recieved for variable "Cheeseburgers". The alteration of the data held by the variable within the 1st Main lua file does not affect in any way the second copy of the same-named variable that is loaded into the 2nd Main lua file.

Do not "local" the variable that is created in the lua file that will be included within other files. If I state this within the file called "LeeS_PlotToolkitRoutines.lua" the result will be that any file that includes "LeeS_PlotToolkitRoutines.lua" into its contents will not recieve the assignment of the variable or its value:
Code:
local Cheeseburgers = true

--------------------------------

The file that will be added into others (ie, "LeeS_PlotToolkitRoutines.lua") must be listed as a file within an ImportFiles Action-Type.:
Code:
  <InGameActions>
    <ImportFiles id="ToolkitFilesImport">
      <File>LUA/LUA_ToolkitFiles/LeeS_PlotToolkitRoutines.lua</File>
    </ImportFiles>
	...etc....
  </InGameActions>
 
Thanks a bundle, LeeS, that goes way beyond what I was expecting!

I already managed a test, it works great :)
 
Back
Top Bottom