RPG Maker Forums

EDIT: With setInterval to check every 100 milliseconds whether the current map is Scene_Map, it is now working. Still, that approach seems quite dirty to me, so I'd like to hear a more experienced programmer's opinion on the matter :)


My problem with a bit of context, although it probably isn't necessary for the issue at hand:


For a summoning plugin I'm writing, I would like to remove any summoned actors from the party and readd the old party members after each battle. The summoned actors should be visible until the battle scene has completely faded out, but when the map scene fades in, the party should once again consist of the previous members.


Exchanging the actors works flawlessly, but I'm having trouble putting my exchange function at the right position in the code. Currently I'm modifying the updateBattleEnd function from BattleManager. My code boils down to this:


_old_BattleManager_updateBattleEnd = BattleManager.updateBattleEnd;
BattleManager.updateBattleEnd = function() {
// call old function
_old_BattleManager_updateBattleEnd.call(this);
// exchange actors - in the actual plugin, another function is called, but this is the shortest way to replicate the problem
$gameParty.removeActor(1);
$gameParty.addActor(2);
};


Basically, I would like to see this sequence:


- battle ends with actor 1 in the party


- battle scene fades out


- actor 1 is removed from the party and actor 2 is added; the player doesn't see the exchange taking place


- map scene fades in; actor 1 is now no longer in the party, but actor 2 is in the party


But with the code above as a plugin, the exchange already takes place in the battle scene, in the last frames before the scene fades out.


Is there any way to wait until the scene has changed before executing the next lines, or would it be better to modify a different function or approach the problem in a completely different way?


Thank you for taking the time to read this :)


EDIT:


I got it to work with the setInterval function. Every 100 milliseconds I check if the current scene has changed back to a Map_Scene and exchange the actors and clear the interval if that is the case:


_old_BattleManager_updateBattleEnd = BattleManager.updateBattleEnd;
BattleManager.updateBattleEnd = function() {
// call old function
_old_BattleManager_updateBattleEnd.call(this);
// exchange actors
var interval = setInterval(function() {
if (SceneManager._scene.constructor == Scene_Map) {
$gameParty.removeActor(1);
$gameParty.addActor(2);
clearInterval(interval);
}
}, 100);
};


If there is a way to do it more elegantly, I'm open for suggestions!

Latest Threads

Latest Posts

Latest Profile Posts

Day 9 of giveaways! 8 prizes today :D
He mad, but he cute :kaopride:

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.

Forum statistics

Threads
106,040
Messages
1,018,470
Members
137,821
Latest member
Capterson
Top