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

Wavelength

MSD Strong
Global Mod
Joined
Jul 22, 2014
Messages
6,045
Reaction score
5,705
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
32,885
Reaction score
8,240
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,471
Reaction score
1,863
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
193
Reaction score
125
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
301
Reaction score
409
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,991
Reaction score
1,460
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
42,495
Reaction score
14,823
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,991
Reaction score
1,460
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
42,495
Reaction score
14,823
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
193
Reaction score
125
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,501
Reaction score
727
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,828
Reaction score
974
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,501
Reaction score
727
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,828
Reaction score
974
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,501
Reaction score
727
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:

Wavelength

MSD Strong
Global Mod
Joined
Jul 22, 2014
Messages
6,045
Reaction score
5,705
First Language
English
Primarily Uses
RMVXA
Sorry for bumping this so long after the fact, but I just want to sincerely thank everyone who provided answers! I wrestled for a long time over whether I want to allow people to rename my plugins, but decided in the end that it's the right thing to do, and I went with the approach suggested by @Traverse and @estriole (from among the several good solutions offered by you guys):
JavaScript:
wave_slates.script_name = document.currentScript.src.split('/').slice(-1)[0].slice(0,-3).replace(/\%20/g," ");

And then I can use that to, for example, get and parse a plugin parameter:
JavaScript:
wave_slates.max_level = Number(PluginManager.parameters(wave_slates.script_name)["max_lev"]);

It worked so well, and I like it so much, that I decided to use it in all of my future plugins. THANK YOU!! :D
 

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
6,208
Reaction score
7,479
First Language
Indonesian
Primarily Uses
RMVXA
In this plugin
I use a shorter code.
JavaScript:
const pluginName = document.currentScript.src.match(/.+\/(.+).js/)[1]
it is simply a regular expression. Capture specific string from the matching pattern.
The "currentScript" src can be something like "plugins/YourPlugin.js"
The expression /.+\/(.+).js/ means
  • "/" the beginning and ending of Regex declaration.
  • dot expression (.) match ANY character, (+) one or more.
  • "\/" match exactly a character "/".
  • (.+) match ANY character one or more and CAPTURE it. The parenthesis means to capture the string within the scope
  • ".js" match exactly ".js"
The return would be an array, I forgot the value of [0], but [1] means the first captured value, which means your plugin name.

Edit:
Fixing typo
 
Last edited:

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
6,208
Reaction score
7,479
First Language
Indonesian
Primarily Uses
RMVXA
Wouldn't the . in .js here match any single character? :kaoswt: Consider escaping it, i.e. \.js.
You are right, but that does not change the fact it also matches with an exact ".js" :p
 

Another Fen

Veteran
Veteran
Joined
Jan 23, 2013
Messages
608
Reaction score
320
First Language
German
Primarily Uses
In another thread someone pointed out that the Internet Explorer does not support document.currentScript (although I'm not sure how many people would still consider using that one to play Maker games).

I'd probably still consider using that code in places that are quick to find and substitute when necessary though.
 

Latest Threads

Latest Posts

Latest Profile Posts

Ohh man, Weapon animations plugin feels so mandatory. Seeing that same image regardless of the icon of the weapon....ugh :p
Ok so......Maaaaybe I've taken a ''little'' bit of inspiration from FF9 when it comes to battle hud xD

ff9.PNG

Just maybe....
New version of my wife's art for Tundra's opening map. No new version of Katrina yet, but I think this looks awesome.1624062754755.png
Devil May Cry-Style Action Shooter in RPG Maker 2000! | RPG Maker News #75

Forum statistics

Threads
112,352
Messages
1,067,688
Members
146,001
Latest member
iookya
Top