RMMV Inserting code into default's game functionality

HenriqueBG

Villager
Member
Joined
Jan 5, 2021
Messages
8
Reaction score
1
First Language
Portuguese
Primarily Uses
RMMV
JavaScript:
var _Scene_Map_onMapLoaded_base = Scene_Map.prototype.onMapLoaded;

Scene_Map.prototype.onMapLoaded = function () {

    _Scene_Map_onMapLoaded_base.call(this);
    //code
}

I have been using this on some plugins where i need to execute after the map is loaded (events created).
I guess i am inserting code between, or before the onMapLoaded..
don't really know..

I would love if someone could explain me exactly what is going on here.

Step by step, like if i was using the debugger (i tryed this), what am i doing here? is this like a middleware?
 
Last edited:

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
6,055
Reaction score
7,143
First Language
Indonesian
Primarily Uses
RMVXA
It means you're preserving the previous function in order to preserve the previous code. Then add your own.

Code:
var _Scene_Map_onMapLoaded_base = Scene_Map.prototype.onMapLoaded;
This is the code that preserves it.

Code:
_Scene_Map_onMapLoaded_base.call(this);
Then call the preserved code so that the original code is executed.

Code:
   //code
Then add your own.
 

HenriqueBG

Villager
Member
Joined
Jan 5, 2021
Messages
8
Reaction score
1
First Language
Portuguese
Primarily Uses
RMMV
Thank you very much. It makes sense now!
 

Latest Threads

Latest Profile Posts

I once thought about a boss gauntled game. I actually did it.
Stream will be live shortly with some Gex 3! Feel free to drop by!
Snippet from a game I'm working on. Not much happening here. Mostly look at atmosphere. May upload a longer version. Still need to make up some enemy arts.
Been slightly struggling with developing the latest chapter, I think I will downscale my ambitions and make it more linear.

Forum statistics

Threads
109,056
Messages
1,041,687
Members
141,541
Latest member
spectrallax
Top