Question about JS, Parameters and Plugin Command

Discussion in 'Learning Javascript' started by shrap_x, Dec 24, 2015.

  1. SilverDash

    SilverDash Veteran Veteran

    Messages:
    389
    Likes Received:
    153
    First Language:
    Dutch
    Primarily Uses:
    RMMV
    Do with it whatever you want, no credit nothing required.

    Would appreciate it though if you would rename the Silv variable to your own to avoid conflicts ;)
     
    Last edited by a moderator: Dec 31, 2015
    #21
  2. shrap_x

    shrap_x Villager Member

    Messages:
    20
    Likes Received:
    0
    First Language:
    English
    //===========================================================================//Game_Interpreter Plugin Commands//===========================================================================var shrap_x_interpreter = Game_Interpreter.prototype.pluginCommand;Game_Interpreter.prototype.pluginCommand = function (command, args) { shrap_x_interpreter.apply(this); if (command === 'EnableMapDebug') { $gameSystem.EnableMapDebug(args[0]); }};
    Code:
    //===========================================================================//Game_Interpreter Plugin Commands//===========================================================================var shrap_x_interpreter = Game_Interpreter.prototype.pluginCommand;Game_Interpreter.prototype.pluginCommand = function (command, args){    shrap_x_interpreter.apply(this);    if (command === 'EnableFollowerStopLeaderDir') {        $gameSystem.EnableFollowerStopLeaderDir(args[0]);    }};
    Ok, things are shaping up swimmingly except for one lingering issue. How can I make plugin in commands in different javascript files?

    So they are appended to each other. Right now I am exceeding the stack size due to duplicates.

    I figured this was wrong up front but tried it anyway.

    Do I need to modify this with the alias?

    Sorry for asking so many questions.
     
    Last edited by a moderator: Dec 31, 2015
    #22
  3. Iavra

    Iavra Veteran Veteran

    Messages:
    1,797
    Likes Received:
    856
    First Language:
    German
    Do you have your plugin wrapped in an anonymous function?

    Code:
    var MODULE = MODULE || {};    // Your public namespace(function() {    "use strict";                                  // Your entire plugin.         MODULE.PLUGIN = {                              // Your public API. "PLUGIN" needs to be different for each plugin!    };    })();
    Because this is exactly what happens, when you declare public variables and accidently overwrite existing ones.
     
    #23
  4. SilverDash

    SilverDash Veteran Veteran

    Messages:
    389
    Likes Received:
    153
    First Language:
    Dutch
    Primarily Uses:
    RMMV
    It seems he hints that he doesn't know how to alias and that he is just trying something. So even with anonymous functions he would cause it to crash sooner or later.

    If he would have used my template it wouldn't be possible to have a duplicate alias though ;) . No need for an anonymous function. But IF you skip on the anonymous function, you better know exactly what you are doing or things turn ugly. So I would also recommend him using an anonymous function (for now).

    I highly recommend any starting plugin writers to use the anonymous function around all of your code at first. When you get more experienced, drop it later on.

    Also there is a bug in his code:

    shrap_x_interpreter.apply(this);should be:

    shrap_x_interpreter.apply(this, arguments);The other possible problem is that if he did not use an anonymous function, he indeed now declared an (probably accidental) public variable called shrap_x_interpreter which also clutters the global window namespace. On top of that it doesn't sound very unique so if he would create another plugin, it would probably conflict already. Each alias must be unique (per scope).
     
    #24

Share This Page