[MV] Accomodating Plugin Name Changes

0 Members and 1 Guest are viewing this topic.

Level 97
2014 Best RPG Maker User - Engine2014 Most Unsung Member2013 Best RPG Maker User (Scripting)2012 Favorite Staff Member2012 Most Mature Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best RPG Maker User (Scripting)2011 Best Veteran2011 Favourite Staff Member2011 Most Mature Member2011 Best Use of Avatar and Signature Space2010 Favourite Staff Member2010 Most Mature Member
Hey everyone,  I have a question. I was writing a plugin with plugin parameters, and I noticed that the default plugins hard-code the name of the file into their script like this:

Code: [Select]
  var parameters = PluginManager.parameters('SimpleMsgSideView');

That seems like it could cause a problem if a user does not name their version of the plugin the same way that you anticipate (e.g. if a person does not call their plugin "SimpleMsgSideView.js"), so I was thinking of doing this instead:

Code: [Select]
// Get Script Name, in case user unexpectedly altered it
var path = document.currentScript.src;
var scriptName = path.substring(path.lastIndexOf('/')+1).match(/^(.+?)(\.[^.]*$|$)/)[1];

// Set Parameters
  var parameters = PluginManager.parameters(scriptName);

I don't really know JavaScript well enough to anticipate if that will always work though or whether there are situations where the currentScript method won't actually return the right file name, so I was wondering if anyone with more experience knows whether there is a better way to overcome my anticipated problem, or whether it really even is a problem.

« Last Edit: October 31, 2015, 04:33:05 PM by modern algebra »

Level 39
Crownless King
It's only today that I saw this. Do you mean the ability to get the parameters without considering which file name is used?
you can do:

Code: [Select]
var params = $plugins.filter(function(p) { return p.description.contains('<ModernAlgebraPlugin>'); })[0].parameters;

Anything that is contained in there such as params, desc and filename will be contained.

If you like my work, please do support me on Patreon.