[this has been asked on Blockland Content Creators (BCC), and I figured forwarding that here would aid in response.]
So I'm working on an addon that has module loading for the sake of organization. Based on the topic title you should know where I'm going with this.
To try to make this work, I did my searching and ended up finding a
script by Ahead on GitHub that loads files in a "modules folder" with each module inside their own folder, similarly to
loadClientAddons();, except the code is different and unique:
//------------------------------------
// Ahead Client Tools
// Module loading system
// by Ahead (ID: 33159)
//------------------------------------
echo("Ahead Client Tools | Loading main functions");
function loadAheadModules() //function for finding & loading modules; basically it's just loadClientAddOns
{
%dir = "Add-Ons/Client_Ahead/Modules/*/module.cs";
%fileCount = getFileCount(%dir);
%filename = findFirstFile(%dir);
%dirCount = 0;
while(%filename !$= "")
{
%path = filePath(%filename);
%dirName = getSubStr(%path, strlen("Add-Ons/Client_Ahead/Modules/"), strlen(%path) - strlen("Add-Ons/Client_Ahead/Modules/"));
%dirNameList[%dirCount] = %dirName;
%dirCount = %dirCount + 1.0;
%filename = findNextFile(%dir);
}
%i = 0;
while(%i < %dirCount)
{
%dirName = %dirNameList[%i];
echo("Ahead Client Tools | Client checking module: " @ %dirName);
%name = %dirName;
echo("Ahead Client Tools | Loading module: " @ %dirName);
exec("Add-Ons/Client_Ahead/Modules/" @ %dirName @ "/module.cs");
%i = %i + 1.0;
}
}
echo("Ahead Client Tools | Looking for modules");
loadAheadModules();
echo("Ahead Client Tools | Done!");
However, I did my looking, testing, etcetera and found that, of course, it wouldn't work (after editing the file paths, of course), so I figured I can reach out to the forums/BCC to get some help.
I'm not using
exec(); because a user would have to extract the base
server.cs file, add a line to the code, and replace the original file
every time the user adds a module, so instead, by making all the files in a single folder be executed when the initial addon loads, it would make things easier for intrigued users in adding functions to the addon.
All help is appreciated, and I hope you understand what I'm looking for. Thanks.
(Yes, I will elaborate more on specific aspects if needed.)
-----
Update 1: code block received via BCC, will change this as testing is done