How important is IIFE in RMMV?

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
5,573
Reaction score
6,497
First Language
Indonesian
Primarily Uses
RMVXA
@Trihan maybe you would be better to start updating the thread and add "How to expose your variable to global window" because your example in your thread suit best for my example as of "you can not patch someone's plugin without directly edit the file" :p

Because with IIFE is on the way, I could not make an overwrite patch that does an edit like from this
Code:
    Scene_Map.prototype.createAllWindows = function() {
        _Scene_Map_createAllWindows.call(this);
        this.createMinimapWindow();
    };
to this (a separate file plugin that must be placed directly below the plugin)
Code:
    Scene_Map.prototype.createAllWindows = function() {
        _Scene_Map_createAllWindows.call(this);
        do_something_in_between()
        this.createMinimapWindow();
    };
Because _Scene_Map_createAllWindows is private in IIFE.
There was never been a problem like this in RGSS.

Because many people would refer to your tutorial when it comes to plugin making. And not sure if they would bother to read the comments.
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
2,603
Reaction score
1,940
First Language
English
Primarily Uses
RMMV
Yeah, I'd always intended to update it but never found the time. I'll see if I can do so tonight, Theo.
 

Aesica

undefined
Veteran
Joined
May 12, 2018
Messages
1,474
Reaction score
1,366
First Language
English
Primarily Uses
RMMV
@Trihan maybe you would be better to start updating the thread and add "How to expose your variable to global window" because your example in your thread suit best for my example as of "you can not patch someone's plugin without directly edit the file" :p

Because with IIFE is on the way, I could not make an overwrite patch that does an edit like from this
Code:
    Scene_Map.prototype.createAllWindows = function() {
        _Scene_Map_createAllWindows.call(this);
        this.createMinimapWindow();
    };
to this (a separate file plugin that must be placed directly below the plugin)
Code:
    Scene_Map.prototype.createAllWindows = function() {
        _Scene_Map_createAllWindows.call(this);
        do_something_in_between()
        this.createMinimapWindow();
    };
Because _Scene_Map_createAllWindows is private in IIFE.
There was never been a problem like this in RGSS.

Because many people would refer to your tutorial when it comes to plugin making. And not sure if they would bother to read the comments.
Unless I'm not understanding you correctly, of course you can. Consider this:

Code:
(function($$)
{
   // You can still alias and/or overwrite this
   // just like you would any other function
   // because it's referencing an object outside
   // the IIFE scope
   Game_Actor.prototype.skills = function(){};

   // You can also alias and/oroverwrite this
   // as Aesica.SomeCrapPlugin.doStuff
   $$.doStuff = function(){};

   // But you can't touch this one, and why
   // would you want to anyway?
   function parseMyPluginParameters(){};

   // this one is also untouchable from the outside
   let parseMyNoteTags = function(){};
})(Aesica.SomeCrapPlugin);
See, Javascript is the type of language where it's really easy to do things horribly. Looking back at some of my earlier code, especially when I first started learning it, I fell into a lot of those traps and it made things harder to go back and fix later on. "Oh no, all my variables are global! Can I change this function without breaking these other two?"
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
2,603
Reaction score
1,940
First Language
English
Primarily Uses
RMMV
I think he's referring mainly to cases where your plugin creates new classes that don't already exist in the global scope; using an IFFE for that means other plugins can't access your classes unless you provide an interface via which to do so.
 

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
5,573
Reaction score
6,497
First Language
Indonesian
Primarily Uses
RMVXA
Unless I'm not understanding you correctly, of course you can.
Obviously you're not understanding me correctly. My context was in Trihan's tutorial (except if it's already rewritten).

Consider this:
And many of the existing plugins don't consider this. I was not saying it is impossible. Just as far as I can tell, not many do this.
 

Aesica

undefined
Veteran
Joined
May 12, 2018
Messages
1,474
Reaction score
1,366
First Language
English
Primarily Uses
RMMV
Aah, well that's just another example of what I said previously about Javascript having lots of ways to do things horribly. If the new class is something that would potentially be useful to other developers, there's no rule saying it has to be in the IIFE with everything else.
 

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,556
Reaction score
3,812
First Language
English
@Trihan maybe you would be better to start updating the thread and add "How to expose your variable to global window" because your example in your thread suit best for my example as of "you can not patch someone's plugin without directly edit the file" :p

Because with IIFE is on the way, I could not make an overwrite patch that does an edit like from this
Code:
    Scene_Map.prototype.createAllWindows = function() {
        _Scene_Map_createAllWindows.call(this);
        this.createMinimapWindow();
    };
to this (a separate file plugin that must be placed directly below the plugin)
Code:
    Scene_Map.prototype.createAllWindows = function() {
        _Scene_Map_createAllWindows.call(this);
        do_something_in_between()
        this.createMinimapWindow();
    };
Because _Scene_Map_createAllWindows is private in IIFE.
There was never been a problem like this in RGSS.

Because many people would refer to your tutorial when it comes to plugin making. And not sure if they would bother to read the comments.
I wouldn't want to write my plugin that relies on the existence, or non-existence, of some private "_Scene_Map_createAllWindows" though.
 

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
5,573
Reaction score
6,497
First Language
Indonesian
Primarily Uses
RMVXA
I wouldn't want to write my plugin that relies on the existence, or non-existence, of "_Scene_Map_createAllWindows" though.
It won't be a plugin, it will be a patch.
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
2,603
Reaction score
1,940
First Language
English
Primarily Uses
RMMV
Aah, well that's just another example of what I said previously about Javascript having lots of ways to do things horribly. If the new class is something that would potentially be useful to other developers, there's no rule saying it has to be in the IIFE with everything else.
It's not so much about what the rules are as what developers currently do.

I'll give you a prime example of this: One of my most recent commissions is for a menu system plugin that basically rearranges all the windows and adds some window animation/functionality. As part of this, my client wants non-active cursors in windows to blink, but he's also using Galv's image cursor plugin.

That plugin is inside an IFFE, so I wasn't able to edit the update function directly. Thankfully Galv did add a cursor object property to windows that I was able to hook into, but it was still way harder than it otherwise would have been to implement my client's request. :p
 

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,556
Reaction score
3,812
First Language
English
I guess we could all remember to attach the aliased methods to our namespace object

Code:
(function($) {
  var $.oldFunc = func
  Something.prototype.func = function() {
    $.oldFunc.call(this);
    // new stuff
  }
})(MyPlugin)
So that you could then access it via MyPlugin.oldFunc if you wanted to.
 

Aesica

undefined
Veteran
Joined
May 12, 2018
Messages
1,474
Reaction score
1,366
First Language
English
Primarily Uses
RMMV
It won't be a plugin, it will be a patch.
Again, it's not a matter of IIFE vs everything in the global namespace. It's a matter of some plugin devs not thinking of every angle. I tend to write my override functions like this:

Code:
$$.Game_Actor_skills = Game_Actor.prototype.skills;
Game_Actor.prototype.skills = function()
{
   $$.Game_Actor_skills.call(this);
   // other stuff here
};
For that very reason.

Edit: That way, you can just reference Aesica.SomeCrapPlugin.Game_Actor_skills if you really want to.
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
2,603
Reaction score
1,940
First Language
English
Primarily Uses
RMMV
I think that should definitely be the standard for plugin devs going forward. I'll add a bit about that to my tutorial.
 

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
5,573
Reaction score
6,497
First Language
Indonesian
Primarily Uses
RMVXA
@Aesica tell you what, if many started to do like you do, I wouldn't even begin to create this thread in the first place. Because the problem seems like many just di IIFE because of IIFE. So I began to question why is it so important.

I think I've already got your point. You don't need to repeat it. The problem is, do you understand where I came from?
 

Ossra

Formerly Exhydra
Veteran
Joined
Aug 21, 2013
Messages
1,076
Reaction score
845
First Language
English
Primarily Uses
RMMV
@Tsukihime @Aesica That is what I do. All new and old functions and such are shoved into the namespace for the plugin. For MZ, I am creating a shared function that will allow people to grab the namespace and version of a plugin if it is loaded into the project. So if someone really, really needed to do so ... everything is there.
 

Aesica

undefined
Veteran
Joined
May 12, 2018
Messages
1,474
Reaction score
1,366
First Language
English
Primarily Uses
RMMV
@Aesica tell you what, if many started to do like you do, I wouldn't even begin to create this thread in the first place. Because the problem seems like many just di IIFE because of IIFE. So I began to question why is it so important.

I think I've already got your point. You don't need to repeat it. The problem is, do you understand where I came from?
Oh I absolutely get it, but because of that, it might be better for the focus to be on bad and good practices with IIFE vs whether IIFE is good or bad in and of itself. I mean look how long it took for me to figure out what you were actually getting at. :)
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
2,603
Reaction score
1,940
First Language
English
Primarily Uses
RMMV
Do you think it might be an idea to look into the possibility of forming some kind of semi-official "plugin council" of well-known or prolific developers to come up with a plugin standard and/or template for devs to use that will avoid common pitfalls and implement IFFE in the positive ways (avoidance of namespace pollution) without the potential negatives?
 

Aesica

undefined
Veteran
Joined
May 12, 2018
Messages
1,474
Reaction score
1,366
First Language
English
Primarily Uses
RMMV
Do you think it might be an idea to look into the possibility of forming some kind of semi-official "plugin council" of well-known or prolific developers to come up with a plugin standard and/or template for devs to use that will avoid common pitfalls and implement IFFE in the positive ways (avoidance of namespace pollution) without the potential negatives?
I dunno, actually. Would people adhere to its guidelines, or even knew it existed for that matter? It'd depend largely on how much of a reach it was able to have.
 

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
5,573
Reaction score
6,497
First Language
Indonesian
Primarily Uses
RMVXA
I wouldn't want a council that judges on how I would write my code.
However, I don't like a misleading guide or tutorial. If someone wants to stray from the guide, it is their choice and also their fault. Not the guide's fault for making them do something wrong.
 

Aesica

undefined
Veteran
Joined
May 12, 2018
Messages
1,474
Reaction score
1,366
First Language
English
Primarily Uses
RMMV
I wouldn't want a council that judges on how I would write my code.
However, I don't like a misleading guide or tutorial. If someone wants to stray from the guide, it is their choice and also their fault. Not the guide's fault for making them do something wrong.
I think it's less about judging people's code and more about trying to establish a standard that will make plugin creation easier for everyone.
 

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
5,573
Reaction score
6,497
First Language
Indonesian
Primarily Uses
RMVXA
I think it's less about judging people's code and more about trying to establish a standard that will make plugin creation easier for everyone.
The term "council" seems like a group of people that judges your code. But what you're basically saying is a guideline which is fine by me.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

"Let us be absolutely clear about this: "
Miss posting updates of my projects here...miss having time to work on my projects
I'm not sure if it's okay or not, I update it often because I think it's not.
Ami
--- Dumped ---

Hero: Please go out with me!
F.Healer: (Silent In 10 Seconds) I refuse.
Hero: ???
F.Healer: I don't want my friendship with F.Mage is ruined because i'm in your side. so...i'm sorry. (Running)
Hero: (Glass Break SFX)
I really wish to have listened someone's advice regarding writing, because I'm a little stuck.

Guys, if you have a whole story in mind, and you strongly believe it's going to work, make the effort of writing it. Because if you get stuck in a scene, you might have to re-assess it.

Forum statistics

Threads
103,352
Messages
998,969
Members
134,863
Latest member
Tabako
Top