[SOLVED] How to overwrite a "vanilla" function?

Status
Not open for further replies.

TheWarDoctah

Warper
Member
Joined
Dec 15, 2018
Messages
2
Reaction score
0
First Language
Portuguese
Primarily Uses
RMMV
Hi, I'm somewhat new to programming. I'm messing with mouse commands on MV, but I'm altering direct on the rpg_xx.js files, and there are changes that I even don't remember which line was. HAhaha.

Well, how can I create a plugin that my function totally overwrite the original function (on rpg_xxxx files)?
Example:
Code:
Game_Player.prototype.triggerTouchActionD1 = function (x1, y1) {
    if ($gameMap.airship().pos(x1, y1)) {
        if (TouchInput.isTriggered() && this.getOnOffVehicle()) {
            return true;
        }
    }
    this.checkEventTriggerHere([0]);
    return $gameMap.setupStartingEvent();
};
I want to change the whole function in my plugin file, how I can do this? Is there like an equivalent to the way that works on RGSS

Code:
alias :my_method :method
def method
 my_method // if I remember this call the base method, I don't want to execute anything from the original JS function, just overwrite it.
 do_additional_stuff
end
 

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
5,573
Reaction score
6,503
First Language
Indonesian
Primarily Uses
RMVXA
If you're looking a way to make an alias, here is what you need to do.
Code:
(function(){
  var _aliasedTriggerTouch = Game_Player.prototype.triggerTouchActionD1;
  Game_Player.prototype.triggerTouchActionD1 = function (x1, y1) {
    // Your custom code here
    _aliasedTriggerTouch.call(this, x1, y1);
    // Or here
  }
})();
If you're looking a way to overwrite a method, you can just drop a file as a plugin.
Then copy whatever methods you want to overwrite.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,062
Reaction score
13,687
First Language
English
Primarily Uses
RMMV
Easiest way to completely overwrite a method from the core scripts is to copy and paste it into your new plugin, take out everything except the first line and the last line, and put whatever you want in between.
 

TheWarDoctah

Warper
Member
Joined
Dec 15, 2018
Messages
2
Reaction score
0
First Language
Portuguese
Primarily Uses
RMMV
Thank you guys! This work pretty well! Solved.
 

slimmmeiske2

Little Red Riding Hood
Global Mod
Joined
Sep 6, 2012
Messages
7,803
Reaction score
5,212
First Language
Dutch
Primarily Uses
RMXP

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

 
Status
Not open for further replies.

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

Latest Threads

Latest Profile Posts

Why is there so much month left at the end of money? D=
Hello humans! How goes your day in this journey of living? I hope it is good, for I am human like you, and I am feeling great! Worship the altar.
Sand is basically small rocks

Forum statistics

Threads
105,625
Messages
1,015,041
Members
137,285
Latest member
AndrewRobertson
Top