Poor implementation of plugin aliasing?

if the plugin writer doesn't want you accessing the original function, then probably you shouldn't be accessing it. even if he does open up access to the alias, you can't guarantee that it's not tainted. like if 10 people modify the same function, which is the 'correct' one? but if you still want the true original version, make a separate plugin that has priority over theirs and save the alias to the untainted function.
sometimes we need the alias for making compatibility patch. we might not need the true original version (MV default). but we might need the version before scripter x modify it. because simply... it's for compatibility patch for that scripter x...

by losing the alias... we cannot do anything but to overwrite the code (which mean the compatibility might break later if the scripter x update his plugin and change something..).

in my opinion we should always open up access to the alias. don't remove the 'link' in the middle.
kadokawa wrap his code inside:

(function() {...})();which mean his alias is Private variable...

so it won't be like you said... since that variable name is only valid inside those function.
I don't understand what you're saying.

Yes, the plugins are wrapped inside a function.  But each one of them that aliases Game_Interpreter's pluginCommand function has a call to the aliased function right at the start.  That means it's going to look through every plugin that aliases that function, searching for the one that recognizes the command - and even when it finds it, it's still going to let the rest of them process their testing to see if they want to do something with it too.

Are you saying that's NOT going to happen?  How does it find the right plugin to use, then, without going through all 100 of them, if that's how many you have?
I think estriole posted on the wrong thread.
the main issue I am having is: variable_name ... it should be: variableName
That is hardly anything that's going to affect efficiency of the script.
its javascript standards to use the concept of camelCaseNames its my only issue wiht the code you shown. everything else looks fine to me and I see no issue with it
And it's completely off topic.

You don't see an issue with having every single plugin check if it's the one to execute the command, when the first one that checks is the one that needs to do it?  You don't see a performance issue with running ALL the checks in ALL the plugins, when you could reduce the number of plugins that are checked just by stopping the recursion when you've found the right one?
its javascript standards to use the concept of camelCaseNames its my only issue wiht the code you shown. everything else looks fine to me and I see no issue with it
You have to remember a lot of people are coming from a ruby background with no prior knowledge of other languages. So its likely a lot of the budding talent will use '_' to delimit their working on function and variable names.

And as shaz said, it has zero impact on the performance of the code, or the readability, or the reliability, or anything. Its just a personal preference. 🙂

On topic - I personally dont like the plugin command structure at all and would prefer to stick with script calls. Especially with the new and improved script call box <3
And it's completely off topic.

You don't see an issue with having every single plugin check if it's the one to execute the command, when the first one that checks is the one that needs to do it?  You don't see a performance issue with running ALL the checks in ALL the plugins, when you could reduce the number of plugins that are checked just by stopping the recursion when you've found the right one?
wait... sorry... i guess i misunderstand what you mean earlier...

i misread your post. and i though the problem lies with same aliased name used over and over again.

(i read it at 3 am btw >.<)

now i see what you mean 😀 .

how about creating a hash containing your command keyword (sorta like imported variable we always use)

then access it like hash instead if's.

example:

var hashname = hashname || {};   <<<< init if people haven't register any command...

hashname["COPY_EVENT"] = Game_Interpreter.prototype.myfunction;  << register our command here... just like aliasing... 😀

at the top of the plugin. just like our old imported 😀 .

edit: this might need at the bottom of the plugins after we create the Game_Interpreter.prototype.myfunction

if we put it above. it might throw error maybe?

then to access it maybe?

in game interpreter:

  var est_myalias = Game_Interpreter.prototype.pluginCommand;  Game_Interpreter.prototype.pluginCommand = function(command, args) {     if(hashname[command.toUpperCase()]) return hashname[command.toUpperCase()].call(this,args);     return est_myalias.call(this, command, args);  };edit: changed to call the alias last so if key found. don't need to interpret it again if we do found the match..

<also let's call the if blablabla above as return hash access for now>

i'm not 100% sure though. 😀 . need some test first

but by my logic it could work...

ex:

scripter a => alias original mv plugin command

                     add return hash access like above.

                     when executed it will check original mv plugin command / any people alias the plugin command

                     then stop when reaching return hash access. execute the function.

edit: since i change calling alias after return hash access. then the aliased might not executed at all if found match

scripter b => alias scripter a

                     add return hash access

                     when executed. it will run the alias first. and stop when reaching return hash access at "scripter a"                      the add return hash access in this modification is never executed.

edit: since i change calling alias after return hash access. then the aliased might not executed at all if found the command match

viable??? if yes... can we decide on community variable name for the hash (like our beloved imported... btw who the first scripter that use imported? anyone know?)

edit2: some example 'full' code:

var est_myalias = Game_Interpreter.prototype.pluginCommand;Game_Interpreter.prototype.pluginCommand = function(command, args) { if(hashname[command.toUpperCase()]) return hashname[command.toUpperCase()].call(this,args); return est_myalias.call(this, command, args);}; Game_Interpreter.prototype.myfunction  = function(args) {      // do something here}; var hashname = hashname || {};hashname['COPY_EVENT'] = Game_Interpreter.prototype.myfunctionedit 3: by calling the return hash access first before the alias... we're also indirectly 'forcing' people to also use the hash access. if using aliasing like what we currently do... it will be forced the plugin command checking to behind.

(except if you put your plugin check before the calling alias too and place the plugin at the top most of plugin manager LOL)

not to mention if many scripter use this method... it might have many duplicate if's check for hash value.

when checking 'default aliasing' plugin command

so i'm not sure... is this a good approach or not.

ex:

scripter a = alias like usual

scripter b = use hash access.

scripter c = use hash access.

scripter d = use hash access.

when the command for scripter a plugins show up... it will execute 3 duplicate ifs check before executing scripter a plugin command...

sorry for so many edit... while typing this... more idea show up. 😀 .
I have not read through all of your post, but yes, the hash idea is what had been discussed a little bit on the previous page.

I wouldn't put the check in the Game_Interpreter pluginCommand though, because any scripters who did not want to go with this idea would still write their plugins the same way, and it would still loop through them all before it got to the 'base' one.  I'd change the function above it - the command123 (whatever the number is - I'm on my way out and don't have time to pull it up).

How many people would be willing to use that kind of hash in their plugins, in order to improve the game's performance?  If enough people are interested, it might be worth looking into further.  Dekita has already said he doesn't like plugins at all, and Darkness Falls has made it clear that he doesn't even see an issue, so that's two who are out.  I probably wouldn't pursue it unless there were a good number who were interested in using that approach.
I don't see an issue either. The perfomance impact is probably very low.
I don't see an issue either. The perfomance impact is probably very low.
I was told in a previous (ruby) topic that my practice of creating method calls for almost everything (ie: premature abstraction) is terrible and will lead to huge performance impacts since people tend to have more than a couple scripts.


I'm assuming javascript has the same issue.
I don't see an issue either. The perfomance impact is probably very low.
The issue is magnified because we're now talking about developing for mobile platforms, which don't have the processing power of a PC. If you're only building a game for PC's then you don't have as much to worry about, but for those of us who want to tap into the 'app' market, it's a sea change in the way we need to think about things.

Lots of things having a small impact on performance add up. From what I've seen so far, getting a decent game running is going to take squeezing blood from a stone. Those developers that take the time to wrap their heads around this and do everything they can will get some solid games out there. I worry about the coming glut of games that will simply suck balls on the majority of Android devices...

Back on topic: I'm down with the hash. Worst case it's something that we can rewrite into plugins that don't use it (speaking of our own projects, not what's publicly distributed). The more plugin developers that use it though, the simpler that job will be.

#useTheHash
I made some tests to try and get an idea of what would be the effect of this. It wasn't tested with real scenarios, but I've cut the numbers by half to make up for it:

With 100 plugins changing the pluginCommand method, if you execute over 200 plugin commands per frame, you may get some fps drop.

Of course, this sums up with anything else being done at the same time, but it's still a very small difference.

If we are going to try and improve RM's perfomance, there's other stuff we can do that would help much more (for instance, my Pathfinding cache makes a giant difference when pathfinding is used).

On a side note, if someone were to use like 1,000 plugins that alias the pluginCommand method, JS will probably crash thinking it got stuck on a loop.
I made some tests to try and get an idea of what would be the effect of this. It wasn't tested with real scenarios, but I've cut the numbers by half to make up for it:


With 100 plugins changing the pluginCommand method, if you execute over 200 plugin commands per frame, you may get some fps drop.


Of course, this sums up with anything else being done at the same time, but it's still a very small difference.


If we are going to try and improve RM's perfomance, there's other stuff we can do that would help much more (for instance, my Pathfinding cache makes a giant difference when pathfinding is used).


On a side note, if someone were to use like 1,000 plugins that alias the pluginCommand method, JS will probably crash thinking it got stuck on a loop.
200 plugin commands per frame, meaning, making 200 method calls?


I'm sure the base engine already makes tons of calls every frame...
200 plugin commands per frame, meaning, making 200 method calls?

I'm sure the base engine already makes tons of calls every frame...
No, I mean one or more events with 200 plugin commands added by the user. The game would then go through 100 method calls for each of those.
I myself am planning on doing the following.

I assume someone out there is making a plugin that allows you to store plugin commands in an Object, with property x being set to a function.

(Quick note, JavaScript technically doesn't have hashes, it stores everything in properties. JavaScript was made originally with HTML in mind, and, by extension, the DOM. $object['property'] is functionally the same to $object.property, something not possible with hashes.)

Anyway, the plugin would check if such a plugin exists. You can easily do this by doing something like:

var command = "MyPluginCommand";var pcFunc = function(args) {  ...}if(Creator && Creator.PluginCommandManager) {  Creator.PluginCommandManager.addCommand(command, pcFunc);}
I myself generally create a namespace for my own plugins, but that's not a requisite.

I always add a fallback that actually aliases the plugin command.

This does make your code slightly slower, but it does allow your script to be both independent and a bit more optimized when the plugin command manager is implemented.

It's not ideal, but it's a method. I myself will work on one, but it would be great if this was put in some standard like MVCommons or something.

A simple way to implement this would be something like:

+function() {  var _pluginCommands = {};   var PluginCommandManager = function() {  }  PluginCommandManager.addCommand = function(command, pcFunc) {    _pluginCommands[command] = pcFunc;  }   var _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;  Game_Interpreter.prototype.pluginCommand = function(command, args) {    if(_pluginCommands.hasOwnProperty(command)) {      _pluginCommands[command].call(this, args);    } else {      _Game_Interpreter_pluginCommand.call(this, command, args);    }  };}
I'd rather use hasOwnProperty here instead of directly checking if it exists, as you could actually run standard object methods this way.

Also, CC0.
I know Javascript doesn't have hashes - that's why I added the "Using Ruby terminology" note 😉
I know Javascript doesn't have hashes - that's why I added the "Using Ruby terminology" note 😉

Actually theres whats called the "poor mans implementation of hashes" in JS:

Consider the following:

var a = {"apples": 3, "oranges": 4, "bananas": 42}; var array_keys = new Array();var array_values = new Array();for (var key in a) { array_keys.push(key); array_values.push(a[key]);}alert(array_keys);alert(array_values);And consider the concept of "Shims" which is supported in ES5 using Object.keys and .map

var keys = Object.keys(myHash);var values = keys.map(function(v) { return myHash[v]; }); 😀
How does that qualify as a hash in any way (the first example)? Both arrays aren't backed by the object and will still hold references to their "keys" and "values", even after you remove them from the object.

Original thread: https://forums.rpgmakerweb.com/threads/poor-implementation-of-plugin-aliasing.50237/