Temporarily Overwrite a Function

In Scene_Map we have a function isBusy currently this doesn't check if the $gameMessage.isBusy();

I want the game to not change scenes if a message is being displayed.

In my script where I display a message I then overwrite the Scene_Map.isBusy() to return $gameMessage.isBusy();

After that I push my next Scene and as expected it doesn't change until my message is done being displayed. Good.

During the custom scene I then change the Scene_Map.isBusy() back to the original.

Is this the best way of doing this?

I am changing the Scene_Map.isBusy only for this specific script at a specific time.

Any insight would be great. Currently it works great but I have a feeling it may not be the best way.
In Scene_Map we have a function isBusy currently this doesn't check if the $gameMessage.isBusy();

I want the game to not change scenes if a message is being displayed.

In my script where I display a message I then overwrite the Scene_Map.isBusy() to return $gameMessage.isBusy();

After that I push my next Scene and as expected it doesn't change until my message is done being displayed. Good.

During the custom scene I then change the Scene_Map.isBusy() back to the original.

Is this the best way of doing this?

I am changing the Scene_Map.isBusy only for this specific script at a specific time.

Any insight would be great. Currently it works great but I have a feeling it may not be the best way.

dont do this do:

Code:
var oldSomethingPrototypeMethodNameMethod = something.prototype.methodName;something.prototype.methodName = fucntion() {    oldSomethingPrototypeMethodNameMethod.call(this);    // Your stuff here ...}
Currently it is:

COLD.BREED.aliasSMapIsBusy = Scene_Map.prototype.isBusy;somefunction(){ Scene_Map.prototype.isBusy = function() { return $gameMessage.isBusy(); };}//in the scene//Gets set back to normalScene_Map.prototype.isBusy = COLD.BREED.aliasSMapIsBusy;Works good but wondering if there is a proper way.
You could just set a local flag in your plugin's anonymous function and set it to true/false and react accordingly.
You could just set a local flag in your plugin's anonymous function and set it to true/false and react accordingly.
Good suggestion, I have changed it to a function that overwrites Scene_Map.isBusy with a true or false input.

This way I can can use it in other scripts as well.

Original thread: https://forums.rpgmakerweb.com/threads/temporarily-overwrite-a-function.51488/