Temporarily Overwrite a Function

Jeremy Cannady

Coldfire
Veteran
Joined
Oct 25, 2015
Messages
449
Reaction score
268
First Language
English
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.
 

DarknessFalls

Rpg Maker Jesus - JS Dev.
Veteran
Joined
Jun 7, 2013
Messages
1,393
Reaction score
210
First Language
English
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 ...}
 

Jeremy Cannady

Coldfire
Veteran
Joined
Oct 25, 2015
Messages
449
Reaction score
268
First Language
English
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.
 

Iavra

Veteran
Veteran
Joined
Apr 9, 2015
Messages
1,797
Reaction score
863
First Language
German
Primarily Uses
You could just set a local flag in your plugin's anonymous function and set it to true/false and react accordingly.
 

Jeremy Cannady

Coldfire
Veteran
Joined
Oct 25, 2015
Messages
449
Reaction score
268
First Language
English
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.
 

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

Latest Threads

Latest Posts

Latest Profile Posts

I should realize that error was produced by a outdated version of MZ so that's why it pop up like that
Ami
i can't wait to drink some ice after struggling with my illness in 9 days. 9 days is really bad for me,i can't focus with my shop and even can't do something with my project
How many hours have you got in mz so far?

A bit of a "sparkle" update to the lower portion of the world map. :LZSexcite:
attack on titan final season is airing tomorrow, I'm excited and scared at the same time!

Forum statistics

Threads
105,882
Messages
1,017,231
Members
137,607
Latest member
Maddo
Top