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

Post Reply
User avatar
SegFault22
Member
Posts: 870
Joined: Mon May 21, 2012 03:17
Location: NaN

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

by SegFault22 » Post

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.
Last edited by SegFault22 on Sun Nov 10, 2013 07:18, edited 1 time in total.
Resources are abundant; only money is scarce. People should not have to work hard and remain poor just to pay for the needs of survival.
Society can thrive without money - but only if productive members of society are rewarded for being productive.

User avatar
fairiestoy
Member
Posts: 191
Joined: Sun Jun 09, 2013 19:25
Location: Germany

by fairiestoy » Post

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
Last edited by fairiestoy on Sun Nov 10, 2013 08:23, edited 1 time in total.
Interesting about new things is, to figure out how it works ...

User avatar
PilzAdam
Member
Posts: 4026
Joined: Fri Jul 20, 2012 16:19
GitHub: PilzAdam
IRC: PilzAdam
Location: Germany

by PilzAdam » Post

Maybe you should use a modpack.

User avatar
SegFault22
Member
Posts: 870
Joined: Mon May 21, 2012 03:17
Location: NaN

by SegFault22 » Post

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.
Resources are abundant; only money is scarce. People should not have to work hard and remain poor just to pay for the needs of survival.
Society can thrive without money - but only if productive members of society are rewarded for being productive.

Post Reply

Who is online

Users browsing this forum: JuanjoPM and 5 guests