RMMZ Plugin Parameters: Any way to accept a Renamed File?

Wavelength

MSD Strong
Global Mod
Joined
Jul 22, 2014
Messages
5,795
Reaction score
5,352
First Language
English
Primarily Uses
RMVXA
Pretty simple question, but one that has been vexing me (as well as my client). Let's say I am writing a plugin called Wavelength_Plugin_1.js but a user saves the file into the project as Very_Cool_Plugin.js. I would still like the plugin to be able to do its job.

When I'm writing the plugin code, is there any way to do either of these?
  • Get whatever name the user has renamed this plugin as, and store it into a variable
  • Use some kind of syntax or keyword to accept whatever name the user has renamed the plugin as
    • For example, something like PluginManager.parameters(pluginName)["first_parameter"] instead of PluginManager.parameters("Wavelength_Plugin_1")["first_parameter"]
Essentially, I don't know what my user will rename the JS file as, but I want the plugin to work and still be able to accept Plugin Parameters. Is this possible, or is it a standard that users should never rename the file for MV/MZ plugins?
 
Last edited:

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
31,766
Reaction score
7,868
First Language
German
Primarily Uses
RMMV
yes, I remember some people using code to make parameters independent of the filename at the beginning of MV (during the first year or so).
but that practise fell out of use because too many plugin programmers didn't use this more complex code, and the few who knew how to stopped bothering that extra work after everyone had been "trained" to not rename the plugins.

If I remember correctly @Shaz was one of the programmers who knew how to do this.
 

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
2,223
Reaction score
1,630
First Language
EN
Primarily Uses
RMMZ
I've seen this done by including a specific string in the description and using that to identify the plugin in lieu of its name, e.g.
JavaScript:
/*:
 * @target MZ
 * @plugindesc Non-fixed plugin filename test. <myPlugin>
 */

(() => {
    // Identifying header data.
    const ID = '<myPlugin>';
    // Fetch filename from a plugin with matching description tag.
    let f = ($plugins.find(p => p.description.includes(ID)) || {}).name || '';
    // Test!
    SceneManager.showDevTools();
    console.info('Plugin file name is ' + f);
})();
I personally avoid doing this because it can make plugins harder to identify in various situations (support, credits, etc); your choice though~ :)
 

Traverse

Veteran
Veteran
Joined
Jul 3, 2014
Messages
162
Reaction score
103
First Language
English
Primarily Uses
There is a way to do it. I used to do it for plugins/scripts I made for MV (not that I ever posted more than 1 or 2 in public).
JavaScript:
var scriptName = document.currentScript.src.split('/').slice(-1)[0].slice(0,-3)
var parameters = PluginManager.parameters(scriptName)
Basically, you're fetching the filepath of the script and extracting the portion of it that corresponds to the filename of the js script file. It doesn't have to be done the exact way above, you can use whatever string manipulation functions you prefer to chop up the filepath string.

I dunno why it never caught on among other coders, I always assumed it was because there might have been some technical issue with trying to load the filepath for web-deployed or phone-deployed games.

But maybe they just couldn't be bothered or like caethyril, they deliberately didn't want people renaming the plugins for whatever reason.
 
Last edited:

casper667

Casper Gaming
Veteran
Joined
Mar 15, 2012
Messages
244
Reaction score
339
First Language
English
Primarily Uses
RMMZ
Renaming plugins is not recommended, but I don't think there's any technical issues that would make what you want impossible to do.

However, filename is also how the MZ editor provides in-editor warnings to users about plugins that are incorrectly ordered or plugins that are missing a dependency. As others have brought up it might also make debugging/crediting/support harder. On the other hand, I don't think there is any benefit to renaming a plugin.
 

Eliaquim

Hakuen Studio
Veteran
Joined
May 22, 2018
Messages
1,776
Reaction score
1,197
First Language
Portuguese - Br
Primarily Uses
RMMZ
Hi!
I think people already offers some solution!
There is a thing that comes to my mind, when renaming plugins, is the plugin command feature(for MZ). When you enter a plugin command it stays on the event page with the plugin name. I had experiences changing the plugin name when I was testing, and I had to update the events.
So don't know exactly if it is safe changing names(if a project is already being made).
 

Shaz

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
40,740
Reaction score
14,002
First Language
English
Primarily Uses
RMMV
I use a method similar to the one shown by @caethyril.

The only time it really matters is if you have plugin parameters. If your plugin just has plugin commands, nor nothing at all, it can be any name. But if it has plugin parameters, you need to be able to retrieve the correct line from the plugins.js file.

The above works for both MV and MZ.
 

Eliaquim

Hakuen Studio
Veteran
Joined
May 22, 2018
Messages
1,776
Reaction score
1,197
First Language
Portuguese - Br
Primarily Uses
RMMZ
Hey, @Shaz If I really get what you mean, I think at least for MZ, the plugin name matters for the plugin commands.
I mean, if you have an event with a plugin command already set up, and then you change the plugin name, you will have to go to that event to correct the plugin command to the new name.
button1.PNG
The event will look for that plugin name, because the Plugin manager also registers the plugin commands using their names(I didn't check, but perhaps it has a reference in the .json file too?):
manager commands.PNG
So I believe if you change the name in a project already ongoing, you will have to change the event references too.
 

Shaz

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
40,740
Reaction score
14,002
First Language
English
Primarily Uses
RMMV
If you haven't used the plugin in any commands yet, you can name it whatever you like. But you'll have trouble if you started using it as one name, added plugin commands, then decide for whatever reason to rename it.
 

Traverse

Veteran
Veteran
Joined
Jul 3, 2014
Messages
162
Reaction score
103
First Language
English
Primarily Uses
Needing to specify the name of a plugin for the Plugin Command is only something that got introduced for MZ.

In MV, you didn't specify any plugin name.

You just directly put the name of the command followed by its parameters/arguments. It was basically a stripped-down version of the Script Call command that only had one line of text entry to call a single function (and you still had to modify Game_Interpreter to add the functions when making plugin commands too, so there wasn't much difference between making plugin commands and making Script Call functions for the coder either).

I think if two plugins/scripts had clashing Plugin Command names in MV, the one loaded most recently in the Plugin list would overwrite that of the older one.
 

estriole

Veteran
Veteran
Joined
Jun 27, 2012
Messages
1,368
Reaction score
608
First Language
indonesian
There is a way to do it. I used to do it for plugins/scripts I made for MV (not that I ever posted more than 1 or 2 in public).
JavaScript:
var scriptName = document.currentScript.src.split('/').slice(-1)[0].slice(0,-3)
var parameters = PluginManager.parameters(scriptName)
Basically, you're fetching the filepath of the script and extracting the portion of it that corresponds to the filename of the js script file. It doesn't have to be done the exact way above, you can use whatever string manipulation functions you prefer to chop up the filepath string.

I dunno why it never caught on among other coders, I always assumed it was because there might have been some technical issue with trying to load the filepath for web-deployed or phone-deployed games.

But maybe they just couldn't be bothered or like caethyril, they deliberately didn't want people renaming the plugins for whatever reason.
i try this method... thanks a lot for this information... but this method have problem when the file name have spaces... so another string manipulation needed:
Code:
var scriptName = document.currentScript.src.split('/').slice(-1)[0].slice(0,-3).replace(/\%20/g," ");
var parameters = PluginManager.parameters(scriptName)
to replace all %20 back to normal space thus the var parameter point to right plugin parameter.
 

DoubleX

Just a nameless weakling
Veteran
Joined
Jan 2, 2014
Messages
1,802
Reaction score
950
First Language
Chinese
Primarily Uses
N/A
I also take this issue of changing file names into account, even though my way is really dumb:

Documentation -
Code:
 *    # Instructions
 *      1. The default plugin parameters file name is
 *         DoubleX RMMZ Targeting AI
 *         If you want to change that, you must edit the value of
 *         DoubleX_RMMZ.Targeting_AI.PLUGIN_NAME, which must be done via
 *         opening this plugin js file directly
Codes supposed to be edited -
JavaScript:
DoubleX_RMMZ.Targeting_AI = {
    PLUGIN_NAME: "DoubleX RMMZ Targeting AI",
    VERSIONS: { codebase: "1.0.0", plugin: "v1.01a" }
}; // DoubleX_RMMZ.Targeting_AI
 

estriole

Veteran
Veteran
Joined
Jun 27, 2012
Messages
1,368
Reaction score
608
First Language
indonesian
I also take this issue of changing file names into account, even though my way is really dumb:

Documentation -
Code:
 *    # Instructions
*      1. The default plugin parameters file name is
*         DoubleX RMMZ Targeting AI
*         If you want to change that, you must edit the value of
*         DoubleX_RMMZ.Targeting_AI.PLUGIN_NAME, which must be done via
*         opening this plugin js file directly
Codes supposed to be edited -
JavaScript:
DoubleX_RMMZ.Targeting_AI = {
    PLUGIN_NAME: "DoubleX RMMZ Targeting AI",
    VERSIONS: { codebase: "1.0.0", plugin: "v1.01a" }
}; // DoubleX_RMMZ.Targeting_AI
I used to use:
Code:
var EST = EST || {};
EST.StrategyMouse = EST.StrategyMouse || {};
EST.StrategyMouse.pluginName="EST_STRATEGY_MOUSE_CAM";

(function($){
$.Parameters = PluginManager.parameters($.pluginName);

})(EST.StrategyMouse);
so when people change the plugin file name... they also need to edit the code and change
EST.StrategyMouse.pluginName... but i always warn people to not change the filename though... since there's small possibility of they wrecking something (like adding /* or ; in not correct place... or deleting the " it happen once before :D) when editing the code...

now using above solution i modify it to:
Code:
var EST = EST || {};
EST.StrategyMouse = EST.StrategyMouse || {};
EST.StrategyMouse.pluginName=document.currentScript.src.split('/').slice(-1)[0].slice(0,-3).replace(/\%20/g," ");

(function($){
$.Parameters = PluginManager.parameters($.pluginName);

})(EST.StrategyMouse);
hopefully there's no need to change any code anymore when people change the plugin filename
 
Last edited:

DoubleX

Just a nameless weakling
Veteran
Joined
Jan 2, 2014
Messages
1,802
Reaction score
950
First Language
Chinese
Primarily Uses
N/A
How about something like this?
JavaScript:
const srcParts = document.currentScript.src.split("/");
console.log(srcParts[srcParts.length - 1].split(".")[0]);
In my case, document.currentScript.src is this:
Code:
chrome-extension://njgcanhfjdabfmnlmpmdedalocpafnhl/js/plugins/DoubleX_RMMZ_Custom_Key_Maps.js
And console.log(srcParts[srcParts.length - 1].split(".")[0]) prints this:
Code:
DoubleX_RMMZ_Custom_Key_Maps
I wonder if there are some edge cases that I've missed ;)

Edit: To cater with cases like name 1.name 2.js, maybe this can be used:
JavaScript:
const srcParts = document.currentScript.src.split("/");
const names = srcParts[srcParts.length - 1].split(".");
names.pop();
console.log(names.join("."));
 
Last edited:

estriole

Veteran
Veteran
Joined
Jun 27, 2012
Messages
1,368
Reaction score
608
First Language
indonesian
How about something like this?
JavaScript:
const srcParts = document.currentScript.src.split("/");
console.log(srcParts[srcParts.length - 1].split(".")[0]);
In my case, document.currentScript.src is this:
Code:
chrome-extension://njgcanhfjdabfmnlmpmdedalocpafnhl/js/plugins/DoubleX_RMMZ_Custom_Key_Maps.js
And console.log(srcParts[srcParts.length - 1].split(".")[0]) prints this:
Code:
DoubleX_RMMZ_Custom_Key_Maps
I wonder if there are some edge cases that I've missed ;)

Edit: To cater with cases like name 1.name 2.js, maybe this can be used:
JavaScript:
const srcParts = document.currentScript.src.split("/");
const names = srcParts[srcParts.length - 1].split(".");
names.pop();
console.log(names.join("."));
any string manipulation that grab the string of the plugin name would be fine...
in example string operation by Traverse above case:
Code:
EST.StrategyMouse.pluginName=document.currentScript.src.split('/').slice(-1)[0].slice(0,-3).replace(/\%20/g," ");
if the document.currentScript.src =
chrome-extension://njgcanhfjdabfmnlmpmdedalocpafnhl/js/plugins/DoubleX_RMMZ_Custom_Key_Maps.js
then it first will split it by the '/'... then grab only the last one at the array (using slice(-1)) thus getting "DoubleX_RMMZ_Custom_Key_Maps.js"... then slice the extension OUT from the string (using slice(0,-3))
i think it's quite optimal enough...

but any string operation that finally get the filename will works fine... but don't forget to add this string operation at the end...
Code:
.replace(/\%20/g," ")
to replace all those %20 back to spaces...

since if we have Myplugin - Copy.js
it will become Myplugin%20-%20Copy.js and will point to wrong plugin parameter if we use that as it is..
 
Last edited:

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Almost to the finish line!... or the starting... since it's just the demo. :kaomad2:

Having problems with enemy/monster designs. :kaosigh:
While we prepare the official trailer, enjoy this kind-of-second teaser! ^^
-Ele
New Episodes of RPG Shenanigans Uploaded to Youtube!

Episode 5 - Surprise Party!
Youtube Link:
Episode 6 - Killer Gin
Youtube Link:
Episode 7 - Gaia's Melody: Echoed Melodies
(Coming soon!)

Episode 8 - Clarent Saga: Tactics
(Coming soon!)

Episode 9 - Star Shift
(Coming soon!)
When the Map Generator throws in the assets in the most dumbest way possible - your path is blocked :D

Forum statistics

Threads
107,567
Messages
1,030,616
Members
139,671
Latest member
WDRS
Top