[RMMV SCRIPTING] HOW DO I SPLIT MY PLUGIN SOURCE CODE INTO MULTIPLE FILES?
Posts
Pages:
1
Alright, so I've noticed that most RMMV plugins are coded monolithically; that is, all the source code for a single plugin is in a single file. I'd much rather be able to split my plugins into multiple files in subfolders below the main plugin's. That way, said main plugin can have cleaner code.
Problem is, I've no idea how to import a js file from a subfolder. I've googled around a bunch, and nothing I've found seems to have worked.
This won't work:
Neither did including the subfolder in the main plugin dir's jsconfig.json file.
I could just put the modules in the same folder as the main one, but then that'd clutter the user's plugins folder. I'd rather avoid that.
So, how can I use relative pathing to pull a JS source file from a subfolder?
Problem is, I've no idea how to import a js file from a subfolder. I've googled around a bunch, and nothing I've found seems to have worked.
This won't work:
let sourceFile = require('./subfolderName/sourceFileName.js')Neither did including the subfolder in the main plugin dir's jsconfig.json file.
I could just put the modules in the same folder as the main one, but then that'd clutter the user's plugins folder. I'd rather avoid that.
So, how can I use relative pathing to pull a JS source file from a subfolder?
Have you tried calling PluginManager.loadScript from your "main" plugin?
(it is just injecting a script element into the document referring to js/plugins/name)
(it is just injecting a script element into the document referring to js/plugins/name)
How am I supposed to use it? I called PluginManager.loadScript, and then tried to execute a function in the script I tried to load. I got an error about that function not being defined.
Have you tried reading the RPGmaker help file? Maybe it's not possible and the help file may state that.
Have you seen any other game use subfolders in this way? If yes, then you could ask them. If no, maybe that points more to it not being possible.
Have you seen any other game use subfolders in this way? If yes, then you could ask them. If no, maybe that points more to it not being possible.
I have read it. It's not very good for learning the API :/
And while I haven't seen other RMMV games use subfolders as I've been wanting to, that doesn't mean I should just take it as impossible; that's awfully defeatist. For all I know, it could just be uncommon knowledge or hard.
Oh, and I'm sorry I forgot to mention how I used loadScript. Here:
Another thing I tried was that same thing, but pathName was "plugins/jsImportTest.js". That made the game window stuck at a black screen.
And while I haven't seen other RMMV games use subfolders as I've been wanting to, that doesn't mean I should just take it as impossible; that's awfully defeatist. For all I know, it could just be uncommon knowledge or hard.
Oh, and I'm sorry I forgot to mention how I used loadScript. Here:
let pathName = './jsImportTest.js'; // Has a function called Thing()
PluginManager.loadScript(pathName);
Thing(); // Throws an error about Thing() not being defined.
Another thing I tried was that same thing, but pathName was "plugins/jsImportTest.js". That made the game window stuck at a black screen.
I'm not suggesting you give up, but that you face the strong possibility you can't do this. To my knowledge no (or very few) RPGmaker programs support subfolders in any way. If subfolders don't work for any other resource folders, which would need to be tested I don't know MV, then that would be another clue this isn't possible. It's unlikely they would enable subfolders for just plugins.
I would think that if this was possible you would have found some information on it by now, assuming you did sufficient searching. A feature like this wouldn't be so hidden and mysterious. The obvious ways of doing it don't work. I highly doubt if they did add this ability, that they would make it so difficult to use. So, you know...
I think maybe you're being a little too optimistic. I'm not being defeatist, I'm being realist based on the evidence and my experience with RPGmaker programs(a long ass time). Good luck, but perhaps your time and effort would be better spent finding a way to work within the limits of the program. Something that has always been sort of a golden rule of RMs since like 1995 heh.
I would think that if this was possible you would have found some information on it by now, assuming you did sufficient searching. A feature like this wouldn't be so hidden and mysterious. The obvious ways of doing it don't work. I highly doubt if they did add this ability, that they would make it so difficult to use. So, you know...
I think maybe you're being a little too optimistic. I'm not being defeatist, I'm being realist based on the evidence and my experience with RPGmaker programs(a long ass time). Good luck, but perhaps your time and effort would be better spent finding a way to work within the limits of the program. Something that has always been sort of a golden rule of RMs since like 1995 heh.
Fair enough; I can face that. If it's as you say (that subfolder modularization isn't supported for RMMV plugins), I'll deal with it. Though, it'd be awfully disappointing; with how inconvenient it is, monolithic programming should've died out in the early 2000s :/
No, Javascript and Ruby are real coding languages; by default, they don't have this issue themselves. This is just a flaw in RM's design; other engines like Unity (even back when it supported JS) didn't have this issue. Neither did pygame or cocos-2dx, and it's a lot harder to make games with those than RM.
I'll keep looking into things. If I find the solution, I'll post it here.
I'll keep looking into things. If I find the solution, I'll post it here.
Pages:
1














