Allows scripts to retrieve their parameters without having to know their current filename.
How to Use
If your plugin is using parameters, it might very well crash if a user renames the file. To prevent this, add an arbitrary string to your @plugindesc, like this:
/*: * @plugindesc My amazing plugin * <Iavra AmazingPlugin> */By putting "<Iavra AmazingPlugin>" in a new line, we effectively hide it from the Maker. You can use any string you want, but make it distinct enough that it wouldn't just randomly appear in some other plugin's description.Now go on to replace this call
var params = PluginManager.parameters('Awesome Plugin'); // File is named Awesome Plugin.jswith this
Code:
This will iterate over all plugins (really just a JavaScript object containing the filename, description and parameters of all plugins) and see if their description contains your id. We take the first one (make sure your id is unique by prefixing it with your own name or namespace) and retrieve it's parameters.Tada, you get your parameters and your users are able to freely rename all your files.var params = $plugins.filter(function(p) { return p.description.contains('<Iavra AmazingPlugin>'); })[0].parameters;If you don't need to worry about being compatible with Internet Explorer (which might cause a whole lot of other issues, anyway), you can also use this solution, which is completely independent from your plugin name and can simply be copy-pasted:
var params = PluginManager.parameters(/([^\/]+)\.js$/.exec(document.currentScript.src)[1]);This will get the path of the currently executing script (which has to be your plugin) and match everything after the last slash, but before ".js" and the end of the path, or in other words: The file name. This is then given to PluginManager.parameters() and used as normal.Terms of Use
Free to use for both commercial and non-commercial games.
Credits
No credits needed, since this doesn't add any actual functionality to the game.