Am I Aliasing right?

So I'm pretty new to the rpg maker scripts/plugins thing as I never used them in Xp or VXA, but I have some experience in generell coding.

I've read that Aliasing is good practice for many reasons and got it for the most part... I think... ^^

Anyhow I'm trying to recreate a SkipTitle script I saw online but it didn't use aliasing, so I looked at http://forums.rpgmakerweb.com/index.php?/topic/47215-tutorial-the-absolute-basics-of-plugin-making/

and the pre-made plugins for ideas how to do this properly.

So in the posted tutorial it says that you sometimes need to "call.this" for it to work but not always?

My question is, am I doing this right?

var _skipScreen_Alias_Scene_GameEnd_commandToTitle = Scene_GameEnd.prototype.commandToTitle;Scene_GameEnd.prototype.commandToTitle = function() { this.fadeOutAll(); if(Number(params["forbid_Title"]) == 1) { SceneManager.goto(Scene_Map); } else { SceneManager.goto(Scene_Title); }};Thank you in advance ^^
You are overwriting the function in this case, which means your plugin will be imcompatible with everything else that deal with it, unless it's placed above them in the plugin manager. For proper aliasing, you need to actually call the variable you created at the first line, like this:

Code:
var _skipScreen_Alias_Scene_GameEnd_commandToTitle = Scene_GameEnd.prototype.commandToTitle;Scene_GameEnd.prototype.commandToTitle = function() {    if(Number(params["forbid_Title"]) == 1)    {        this.fadeOutAll();        SceneManager.goto(Scene_Map);    }     else    {        _skipScreen_Alias_Scene_GameEnd_commandToTitle.call(this);    }};
So I bet I'm way of but to me it seems that this way I change the Original but the alias I created stays the same? Because I'm invoking the original and changing it's function right? I'm pretty confused xD
Assuming, that a different plugin changes the function "Scene_GameEnd.prototype.commandToTitle" before yours, the variable "_skipScreen_Alias_Scene_GameEnd_commandToTitle" will contains that plugin's modified version of the function.


Now, if you are storing the function, but never call it, the changes made by the other plugin will be lost, and it will need to be placed after yours, so it can modify your function, instead.
So I save the original ( or the one modified by another plugin) into a new var.

Then I take the original(or modified one)  and change it to my needs.

And I call the saved var when that part of my plugin/script is off.

But what happens when my plugin runs the

if(Number(params["forbid_Title"]) == 1) { this.fadeOutAll(); SceneManager.goto(Scene_Map); } part? Can another plugin that comes after mine still call the original function? or does it need to call the one I saved in a new var?

Hmm... Is there somewhere a tutorial for this? xD
In this case it's a bit different, since you are conditionally overwriting the function, instead of extending it. If some other plugin were to extend the same method after yours, its additions would always be run. You can imagine it like this:

Code:
// original function: Scene_GameEnd.prototype.commandToTitle = function() {    this.fadeOutAll();    SceneManager.goto(Scene_Title);}; // the effective function, after your modification: Scene_GameEnd.prototype.commandToTitle = function() {    if(Number(params["forbid_Title"]) == 1) {        this.fadeOutAll();        SceneManager.goto(Scene_Map);    } else {        this.fadeOutAll();        SceneManager.goto(Scene_Title);    }}; // the effective function, after someone else modifies it: Scene_GameEnd.prototype.commandToTitle = function() {    if(Number(params["forbid_Title"]) == 1) {        this.fadeOutAll();        SceneManager.goto(Scene_Map);    } else {        this.fadeOutAll();        SceneManager.goto(Scene_Title);    }    // code};
So a plugin adds something to it before me.

Then I modify the whole thing thereby making the other plugin useless if mine runs?

But a plugin coming after mine that "just" adds something will run fine but what if  it modifies the function? Will my modification stop running then?

And what good does the alias do when it is only ever invoked when my modification isn't running anyway?
Usually, when you alias a function, you are adding additional functionality, like this:

var alias_create = Scene_Boot.prototype.create;Scene_Boot.prototype.create = function() {    alias_create.call(this);    initializeMyStuff();};In this case, i want to initialize my plugin when the game starts, so i'm hooking into Scene_Boot.create and call my own function. Someone else might do other stuff before or after my plugin, it doesn't matter for me.

In your case, however, you are conditionally replacing the function, so if "forbid_Title" is set, everything that came before you is ignored. That's fine, because there is really no way you could redirect the user to the map instead of the title, without replacing the original function.
Ahh okay now it does make sense^^ thank you very much that solves my question ^^

Original thread: https://forums.rpgmakerweb.com/threads/am-i-aliasing-right.52156/