Template for MV plugins - a possible recommendation

Well world, because the demo actually lets you see how plugins are generated I would suggest some template, just copy paste it to any plugin you may want to use and then use it.

While probably final plugins may be different, at least we can use the idea of plugin from jQuery and underscore and really... 99% of JS engines, adding some ideas from previous maker and Yanfly's script in the demo:

//=============================================================================// <Plugin Name>// By <Author>// <filename>.js// Version: <version>// Released under <your license>//=============================================================================// This is the imported variable, like you usevar Imported = Imported || {};Imported["MyPluginName"] = true; // or instead of true, a version string, like "1.0.1"// This variable will work as your module, like yanfly's YEP, for examplevar MyName = MyName || {};(function ($) { "use strict"; // Forcing strict mode, I recommend this for YOUR OWN SAFETY...   //My code starts here  // some example  function privateFunction() {    alert("public");  };  function publicFunction() {     privateFunction();  };  function otherPublic() {     $.publicFunction(); // We use $ because it will be our "public space"  };  // we export our values here  $.publicFunction = publicFunction;  $.otherPublic      = otherPublic;})(MyName); // Do you see the MyName here, that is the value of $ above.

This way we won't pollute much the global namespace and we can live al happily together...

And finally a cleaner version of it:

//=============================================================================// <Plugin Name>// By <Author>// <filename>.js// Version: <version>// Released under <your license>//=============================================================================// This is the imported variable, like you usevar Imported = Imported || {};Imported["MyPluginName"] = true; // or instead of true, a version string, like "1.0.1"// This variable will work as your module, like yanfly's YEP, for examplevar MyName = MyName || {};// Plugin starts here(function ($) { "use strict"; // Forcing strict mode  // Imports  // Private variables  // Public variables  // Private classes  // Private functions  // Public classes  // Public functions  // Export area})(MyName); // Do you see the MyName here, that is the value of $ above.// Plugin ends hereOf course I WILL update it on Oct 23... when I can get a full peek about the classes, but this is a good start.

You don't have too do it, but it's clean 😛

FAQ:

Why are you using $ as a parameter?

because it's shorter than MyName, you can use anything, but using $ will help you (and others) than "this is a function from myself"

Of course, using "me", "thisPackage" or not usinf $ is fine, but it is actually a really clever way to remember "this is mine"

Calling from other modules you will have to call it from its full name:

YEP.something()of course, I suggest your classes extensions like "SpriteSomething" go inside your module:

// blah blah(function ($) {    function ChildSprite() { // blah blah blah }; ChildSprite.prototype = Object.create(Sprite.prototype); ChildSprite.prototype.constructor = ChildSprite; $.ChildSprite = ChildSprite;  // continue...What is "use strict"; and Why I should use it?

Use strict is activating strict mode on your code strict mode doesn't make your code slower or faster, not it protects you from code outside, but it protects you by any kind of "code smell" you can do. Please, read the article about strict mode, it will guide you about and make you stop fearing about it, even more, you will embrace it probably when you start doing real code.

See ya on Oct 23th
Does the $ actually mean anything special?
Does the $ actually mean anything special?
It's a variable name. Using a letter would do the same.
Does the $ actually mean anything special?
})(MyName); // Do you see the MyName here, that is the value of $ above.

// Plugin ends here
Does the $ actually mean anything special?
Nah, but it's like a way to say "my plugin" in a short way.

Think about it... if I use $ as a variable name it means "this is my plugin", and you can use it sort when refering to your functions.

Imagine a way of saying I in your code, of course, you have to pass your variable to the function to work like that, but...

it is indeed shorter to write "$.doSomething" than "TsukihimePlugins.doSomething" other people will call by long name, but you can use $ for you 😛
I am not a real fan of strict btw since I don't know the whole strict proceed I prefer to use a non-strict function
It is really nothing to fear, actually, there is no reason to not use strict mode...

You can read more from here.
Looks good. Currently I use concat so there are a lot of self-invoke anonymous functions in final build for easily automatically jshint ._.

Gonna change before the release of MV lol
Nah, but it's like a way to say "my plugin" in a short way.


Think about it... if I use $ as a variable name it means "this is my plugin", and you can use it sort when refering to your functions.


Imagine a way of saying I in your code, of course, you have to pass your variable to the function to work like that, but...


it is indeed shorter to write "$.doSomething" than "TsukihimePlugins.doSomething" other people will call by long name, but you can use $ for you 😛
Oh, I didn't realize you could use $ as a variable name lol
This is a nice template.

Hopefully everyone adopts this template...or at least tries to keep their code clean!
Humm honestly I would go more with this kind of template '3' the coding is kinda similar to the generate demo saw in the demo (well the code structure) but after when it's go with comment it's fairly different and far more organised ...

//==============================================================================// ■ Emoji Engine MV - Origin "AI Core"// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=// Dev Script who permit to have interactive basic AI for your scene.// Created by Nio Kasgami.// Data : 2015/10/05// Version : 1.0.0// Require : NA//==============================================================================//==============================================================================// History// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=// 2015/10/05 - Begin of the conversion Ruby -> JS {Beta}.//==============================================================================//==============================================================================// ■ Game_AI//------------------------------------------------------------------------------// This class handles ai actions. It used within the Game_Personalities class// ($game_personalities).//==============================================================================function Game_AI() { this.initialize.apply(this,arguments);}//==============================================================================// ■ Game_AI {Core}//------------------------------------------------------------------------------ // This section is the place where I initialize everything's and permit to // retrieve the whole AI_Personality[id] informations. It's also inits the // firts actions made by the system. // {exclude sprite configurations}//==============================================================================//----------------------------------------------------------------------------// ○ new function: initialize//----------------------------------------------------------------------------Game_AI.prototype.initialize = function(ai_id) { this._id = ai_id; //wanted to call this just "id" but for some reason it's call a keyword in sublime >_>" this.personality = AI_Personality[this._id]; this.interaction_type = "normal"; this.check_message_type(); this.retrieve_dialogue_and_voices(); this.create_sprite();};//----------------------------------------------------------------------------// ○ new function: check_message_type//----------------------------------------------------------------------------Game_AI.prototype.check_message_type = function() {};//----------------------------------------------------------------------------// ○ new function: retrieve_dialogue_and_voices//----------------------------------------------------------------------------Game_AI.prototype.retrieve_dialogue_and_voices = function() {};//===============================================================================// => END : Game_AI {Core}//===============================================================================I was personally hesitant to use actually Anonymous function actually for my AI since it's can be access everywhere's lol

but I do love how I organize my coding it's clean and show the section clearly

BTW the coding is actually not functionnable it's just a plain conversion from my Ruby Version '3'
Why not use the multiline comment for the top part?

Code:
/*CommentCommentComment*/
Why not use the multiline comment for the top part?
Multi-Line comments are EVIL!! EVIL!!!
Why not use the multiline comment for the top part?

/*CommentCommentComment*/
hummm I though about it lol ...I guess I prefer adding those bar on it lol ? or I am just lazy to change it
Why Hudell?
Why Hudell?
because he know the evilness of thos multi lines!

jk I don't know myself either why multiline are evils xD
Single line comments can easily be triggered in any code editor by selecting some lines and pressing a keyboard shortcut;


When you use multi-line comments and you want to comment a bigger part of the code, you'll have to remove the old closing tag and add it on a new place instead of simply commenting what you want.
Ah.. I see. I find them useful for my case though as I only use it for the header text anyway. So the way I use them is make the multiline start and end first, then just fill it with text afterwards.
Mostly because I took Yanfly's comments and pasted over mine,

I only use multi line comments on docummentation:

Code:
// Noice than it starts with double * because "it's documentation"/** * Generates a powerfull attack on all enemies  * * This function will ignore elemental attributes and such, just for example * @param user  The user than uses the attack * @param skill   The skill used * @param targets An array with the targets * @return true if the function succeeds, false otherwise */ function damageBlahBlah(user, skill, targets) {   // blah blah blah };
Commenting purely so i can follow this - I like your coding style and will probably adopt portions of it in my own js ramblings 😀

Original thread: https://forums.rpgmakerweb.com/threads/template-for-mv-plugins-a-possible-recommendation.45521/