How to: External Configuration Files.
I know that there's lots of mods out there that have values in init.lua that they intend to be changed to taste by the users of the mod. However, not everyone will want to have to open up a lua file and possibly end up breaking some important code.
There is a solution to this, and it is very simple. In fact, I'm surprised so few people use it. Use an external .txt file to store the variables that you want the user to change.
Here's how:
1: In your mod folder, create a file called config.txt
2: Add this inside it:
3: Add these lines in init.lua: (configpath var might be wrong, need to check)
And that is how to read lua from external text files!
Take a look at my ServerExtended mod to see this in action.
There is a solution to this, and it is very simple. In fact, I'm surprised so few people use it. Use an external .txt file to store the variables that you want the user to change.
Here's how:
1: In your mod folder, create a file called config.txt
2: Add this inside it:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- Code: Select all
testvar = true
--Just a boolean value for fun
3: Add these lines in init.lua: (configpath var might be wrong, need to check)
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- Code: Select all
configpath = minetest.get_mod_directory() ..'/config.txt'
dofile(configpath)
if testvar == true then
print("success")
end
And that is how to read lua from external text files!
Take a look at my ServerExtended mod to see this in action.