Questions about how plugins work

Discussion in 'Learning Javascript' started by Windows i7, Nov 24, 2017.

  1. Windows i7

    Windows i7 Veteran Veteran

    Messages:
    311
    Likes Received:
    928
    Location:
    USA
    First Language:
    English
    Primarily Uses:
    RMMV
    I'm assuming that plugin code executes after all the base code does, and that you can thus override base functions.

    As for this bit though... I read that this is a self-invoking function. Is this the entry point for plugins like main in C++?
    (function() {})();

    What exactly is this doing in the sticky template?
    var parameters = PluginManager.parameters('template');
     
    #1
  2. Poryg

    Poryg Pixie of the Emvee kingdom, Ham of a Hamster Veteran

    Messages:
    3,784
    Likes Received:
    9,461
    Location:
    Czech Republic
    First Language:
    Czech
    Primarily Uses:
    RMMV
    Not sure how C++ works, but a self invoking function is an entry point for plugins that need to be executed immediately and won't be executed repetitively.
    And the parameters template is responsible for taking care of plugin parameters (you can see how it works in any yanfly plugins that have parameters you can set in the plugin manager).
     
    #2
    Windows i7 likes this.
  3. Jonforum

    Jonforum Veteran Veteran

    Messages:
    1,574
    Likes Received:
    1,342
    Location:
    Canada / Qu├ębec
    First Language:
    French
    Primarily Uses:
    RMMV
    I'm not sure I understood the whole question but.
    PHP:
    // auto execute when read (no wait to be call)
    (function() {
    // do something
    })();


    // not executed when read, but storing, and wait for call
    function name(){
    // do something
    };

    name(); // now its execute
     
    #3
    Fornoreason1000 and Windows i7 like this.
  4. Kino

    Kino EIS Game Dev Veteran

    Messages:
    515
    Likes Received:
    672
    Location:
    United States
    First Language:
    English
    Primarily Uses:
    RMMV
    (function() {})();

    Creates a new scope for functions and code to be executed in JavaScript. So for example, you could use a self-invoking function to immediately execute code 1, and again create a sense of privacy with all your variables. That's because a function defines new scopes in JavaScript.

    var parameters = PluginManager.parameters('template');
    Allows you to access parameters defined in the pluginManager or the $plugins object in RPGMakerMV. "template" would be looking for the plugin named 'template'; if 'template' isn't found the parameters will be undefined.

    http://endlessillusoft.com/functions-scoping-namespacing/ Talks about scoping and namespacing; take a look.

    This might also help: http://endlessillusoft.com/rpgmaker-mv-es6-part-5-block-scope-variables/
     
    #4
    Windows i7 likes this.
  5. Windows i7

    Windows i7 Veteran Veteran

    Messages:
    311
    Likes Received:
    928
    Location:
    USA
    First Language:
    English
    Primarily Uses:
    RMMV
    Thanks everyone. I just successfully made my first plugin. I cleaned up the template a bit to focus on the code itself (way too many comments for my liking). It successfully runs with MV 1.6.0 beta.
    Code:
    /*:
     * @plugindesc Test plugin
     * @author Windows i7
     */
    
     (function(){
         
        var _Scene_Title_MV = Scene_Title.prototype.drawGameTitle;
       
        Scene_Title.prototype.drawGameTitle = function(){
            _Scene_Title_MV.call(this);
            this._gameTitleSprite.bitmap.drawText("Test", 20, 90, Graphics.width - 20 * 2, 48, 'center');
        }   
        
     })();
    
     
    #5
    Joy Diamond likes this.
  6. Joy Diamond

    Joy Diamond Talkative Veteran

    Messages:
    135
    Likes Received:
    172
    First Language:
    English
    Primarily Uses:
    RMMV
    Congratulations :cool:

    I completely 100% agree -- way too many comments make the code unreadable. I've been doing the same thing & removing comments.
     
    #6
  7. WickedWolfy

    WickedWolfy Touch Fluffy Tail! Veteran

    Messages:
    106
    Likes Received:
    44
    Location:
    East Coast, USA
    First Language:
    En, De, Ru
    Primarily Uses:
    RMMV
    Sorry I am late to the parade, but a note on C++ versus JavaScript.

    C++ is a top-down execution (in most cases). While you can setup states with C++, it becomes a very different language.
    JavaScript, in comparison, is a "state machine design" operation. As Kino mentioned - scopes are created and the code is executed "in scope".
    An easy way to think about it is "event-based system", where you attach your JS code to an event.
    Example: User clicked on "Items" menu item -> default function runs to display appropriate window.
    You attach your code to the same event to display a message, or add/remove items.
    Another example would be UI control: on UI ready and loaded -> create windows to display content.
     
    #7

Share This Page