[SOLVED] Plugin compatibility && Javascript questions

Discussion in 'RPG Maker MV' started by GenisToii, Feb 13, 2016.

  1. GenisToii

    GenisToii Villager Member

    Messages:
    14
    Likes Received:
    0
    First Language:
    Spanish
    Hi everyone!

    I obtained the new RPG Maker MV some days ago and trying to understand the code and how it works. I'm "planning" to create a game where each actor has two classes (physical and magical) and the actor could change of class in battle (ending its turn) and on the menu. 



    Nevertheless, before starting to code I was wondering how the compatibility of plugins would work. I mean, if I have two plugins that change the same class/method/object, what exactly happens? The first configured has dominance or what? Because I was planning to use a plugin or two from Yanfly but if those change something (let's say the add a command in the menu) and I also wanna change it in another way (different command in the menu) but I pretty sure that changing a method in two different ways won't add up the changes together right?  :|
    So, how can I proceed then? How can I modify something modified without getting into the plugin of another person? Is it possible?

    Also, what exactly is called or works this stuff? (Used in Yanfly plugins and MV Commons)


    var Imported = Imported || {};


    Sorry if it's too basic but couldn't find the answer...
     
    Last edited by a moderator: Feb 13, 2016
    #1
  2. Iavra

    Iavra Veteran Veteran

    Messages:
    1,797
    Likes Received:
    856
    First Language:
    German
    Usually, you are extending functions, instead of overwriting them, like this:


    var _alias_pluginCommand = Game_Interpreter.prototype.pluginCommand;
    Game_Interpreter.prototype.pluginCommand = function(command, args) {
    // do something
    _alias_pluginCommand.call(this, command, args);
    };


    If 2 or more plugins extend the same functions, they will be chained, which may or may not work, depending on how you write your plugin. Obviously, you should always keep a function's interface the same (that is, Game_Interpreter.prototype.pluginCommand should always take 2 parameters and forward them in the same order).


    The "Imported" variable is kind of a leftover from older makers and usually used to verify the presence of a plugin, that is needed as a dependency. What the code actually does is assigning the variable to either itself or a new object, depending on if it already exist.
     
    #2
  3. GenisToii

    GenisToii Villager Member

    Messages:
    14
    Likes Received:
    0
    First Language:
    Spanish

    So, let's see if I got it. first you create an instance of the function that you want change and, after it, you modify that function using the already defined instance to make that function to do its initial propose and something else. SO, if that function is again changed by another plugin, it "won't conflict" (usually) with the first modification cause the plugin would do like a modification in chain: the instace of the second plugin would be the already modified instance of the first plugin! Am I right? 
    If it's so, that really clever! Love it hahaha, never thought of it this way  :D

    And thanks for the explanation of the Import thing, just found and example here too: http://stackoverflow.com/questions/18076184/what-is-a-purpose-of-var-a-a-b-1-syntax. But didn't got the "utility" until reading your comment :)
     
    Last edited by a moderator: Feb 13, 2016
    #3
  4. Iavra

    Iavra Veteran Veteran

    Messages:
    1,797
    Likes Received:
    856
    First Language:
    German
    Basically, you have to treat every variable and property in JavaScript as a reference to the actual object in memory (except for primitive data types, like number or boolean, which are directly passed as value). As soon as that object isn't references anymore, the garbage collector will remove it from memory.


    So, by creating a new reference to the old function, we can savely overwrite it without it getting deleted and can refer to it, afterwards.
     
    #4
  5. GenisToii

    GenisToii Villager Member

    Messages:
    14
    Likes Received:
    0
    First Language:
    Spanish
    Great, perfect! Thank you for your answers! :)
     
    #5

Share This Page