This is correct? (SOLVED)

Status
Not open for further replies.

Eliaquim

Hakuen Studio
Veteran
Joined
May 22, 2018
Messages
1,709
Reaction score
1,127
First Language
Portuguese - Br
Primarily Uses
RMMZ
This is the same thing?

1 - Eli.Window_Options_makeCommandList = Window_Options.prototype.makeCommandList;

2 - var _Eli_Window_Options_makeCommandList = Window_Options.prototype.makeCommandList;
 

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
2,117
Reaction score
1,525
First Language
EN
Primarily Uses
RMMZ
Almost the same, yes. ^_^
This is the same thing?

1 - Eli.Window_Options_makeCommandList = Window_Options.prototype.makeCommandList;
This defines a new property on a variable named "Eli" (or redefines it if it already exists) and sets it to Window_Options.prototype.makeCommandList (method reference).
2 - var _Eli_Window_Options_makeCommandList = Window_Options.prototype.makeCommandList;
This defines a new, independent variable on the {enclosing block} (e.g. an IIFE) and sets it to Window_Options.prototype.makeCommandList.

The main difference is scope: putting everything as a property of your own global "Eli" variable (a.k.a. "namespace") means they're accessible outside of the plugin (e.g. by script calls or add-on plugins) but less likely be overwritten by accident. Defining function aliases as variables is perfectly OK though: those usually don't need to be referenced outside of the plugin itself, and if you scope them to your plugin that means other plugins can't access them. Typical usage for both cases:
  • Namespace:
    Code:
    var Eli = Eli || {};  // global variable, set to current value if it exists or an empty object otherwise
    Eli.Window_Options_makeCommandList = Window_Options.prototype.makeCommandList;  // property of global object
    
    (function() {  // IIFE not required here but doesn't affect how things work
      Window_Options.prototype.makeCommandList = function() {
        Eli.Window_Options_makeCommandList.call(this);  // callback via namespace
      };
    })();
  • Local variable:
    Code:
    (function() {  // IIFE for scope: variables defined inside the IIFE are not accessible outside it.
      var _Eli_Window_Options_makeCommandList = Window_Options.prototype.makeCommandList;
      Window_Options.prototype.makeCommandList = function() {
        _Eli_Window_Options_makeCommandList.call(this);  // callback via local variable
      };
    })();
Here's the MDN article on scope in case you're interested: https://developer.mozilla.org/en-US/docs/Glossary/Scope
 

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,299
Reaction score
11,713
First Language
English
Primarily Uses
RMVXA
@Eliaquim when your query is fully resolved please Report your post and ask for it to be closed. Mods might not see a post or change of title but they will see a Report.

[closed]IgnoreMe[/closed]
 
Status
Not open for further replies.

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

Latest Threads

Latest Posts

Latest Profile Posts

Our latest feature is an interview with... me?!

People4_2 (Capelet off and on) added!

Just beat the last of us 2 last night and starting jedi: fallen order right now, both use unreal engine & when I say i knew 80% of jedi's buttons right away because they were the same buttons as TLOU2 its ridiculous, even the same narrow hallway crawl and barely-made-it jump they do. Unreal Engine is just big budget RPG Maker the way they make games nearly identical at its core lol.
Can someone recommend some fun story-heavy RPGs to me? Coming up with good gameplay is a nightmare! I was thinking of making some gameplay platforming-based, but that doesn't work well in RPG form*. I also was thinking of removing battles, but that would be too much like OneShot. I don't even know how to make good puzzles!
one bad plugin combo later and one of my followers is moonwalking off the screen on his own... I didn't even more yet on the new map lol.

Forum statistics

Threads
106,035
Messages
1,018,455
Members
137,821
Latest member
Capterson
Top