Page 1 of 1

Needing a "Dofile"-like operation for a Folder/directory

PostPosted: Sun Nov 10, 2013 04:43
by SegFault22
While working on my latest mod, Morestuff2, I have run into an issue. The mod is broken up into independent "segments", which are separately loaded from a folder. But, with the addition of dozens of chunks of code, there comes a time when the code seems to be too long to quickly access and edit. So, I want to make different scripts for each "part" of a segment, i.e. Crafting or Tools Registry, and load them all, without having to write every path for every script in init.lua, by simply giving the path for the folder that contains all of the scripts. Similar to how the "textures" folder works, where all textures are loaded, but only the folder's path is needed, and any number of textures can be in the folder, but all will be loaded.

However, the "dofile" device only works for single files/scripts, not for entire folders/directories of files/scripts. Using "dofile" and defining a folder's path throws an error, and minetest will not load with such error.

Is there a way to load an entire directory/folder by only defining one path? if so, can you please describe how this would be achieved?
Thank you for your help.

PostPosted: Sun Nov 10, 2013 07:40
by fairiestoy
I ran into a similiar problem once defining a interface for the terminal mod to collect all command scripts in a directory. Up to now, this seems to work between Linux/Windows
Directory collecting routine

PostPosted: Sun Nov 10, 2013 09:50
by PilzAdam
Maybe you should use a modpack.

PostPosted: Sun Nov 10, 2013 19:28
by SegFault22
fairiestoy wrote:I ran into a similiar problem once defining a interface for the terminal mod to collect all command scripts in a directory. Up to now, this seems to work between Linux/Windows
Directory collecting routine

Thank you. I think I can apply this to load all of the scripts within each segment. You have been very helpful.

PilzAdam wrote:Maybe you should use a modpack.

My mod is designed to be installed as a single mod, with multiple "segments", loaded from the segments folder, via "dofile" operations in Init.lua. Each can be enabled/disabled individually. But, I need to split long scripts up into multiple smaller scripts, each containing specific stuff like recipes, item registry, block registry, etc., for a single segment.
I do not intend to use a modpack for this, because I can program functionality used by multiple, independent segments, into init.lua, and there will be no possibility for accidental deletion of the "master mod", which may happen when modpacks are used. But thank you for feedback.