MZ Swap out characters during command input

Hi,

I'm brainstorming about a battle system, but one of the requirements is that the commands of each party member be selectable out of order... and it had me thinking that one way to achieve this is to make characters swappable during command input.

So... prototyping the above using VS_BattleCore and NRP_BattleParallelCommon, I think I can flip through the actors during command selection just fine. A common event will be running that captures key input (left and right) and swaps out characters as indicated in the common event.

The problem is (duh) that the skill set is not automatically refreshed, so everything will turn up empty, and any selection will cause the command input to be cancelled and return to the first party member.

Any ideas on how I can get the list of commands/skills to refresh on the spot when I swap out a character?
Can you not just call the refresh() method of the command/skill list window?
I tried "SceneManager._scene._actorCommandWindow.refresh();" in a script command of the common event, but it doesn't seem to be doing anything.

EDIT: I'm diving deep into the code now and it feels like a rabbit hole so I'll ask the mod to move this to learning JavaScript

I've moved this thread to Learning JavaScript (from MZ Support). Thank you.

Thoughts:
  1. The native systems (Active TPB and Turn-based) allow switching between valid actors with the "cancel" input. This calls the scene's selectPreviousCommand method, which updates input stage/actor and the interface.

  2. Scene_Battle#selectPreviousCommand changes the currently-inputting actor through the BattleManager methods selectPreviousActor -> changeCurrentActor: Active TPB iterates forward, the others iterate backward.
Hi Caethyril, thanks for the thoughts. It seems that selectPreviousCommand returns you all the way to the PartyCommand selection. Btw... so far I haven't been able to make script calls directly to the BattleManager methods work... no errors, just silence... but perhaps that is how it's supposed to work.

I'm now rolling through rabbit holes trying to understand canInput and startActorInput...
It would be _actorCommandWindow.setup to assign a new actor and refresh that window. However, I think the battle scene should update all its windows automatically (update -> updateVisibility -> updateInputWindowVisibility -> changeInputWindow) when the inputting actor is changed, e.g. BattleManager.changeCurrentActor(true);.

Maybe share what you're using to "swap" party members? If you just want to swap within the current party, I'd consider something like this:
JavaScript:
// Swap with next actor (if present)
const i0 = BattleManager.actor()?.index();
if (i0 >= 0 && $gameParty.battleMembers().slice(i0 + 1).some(
  actor => actor.canInput()  // "there is a next actor"
)) {
  BattleManager.changeCurrentActor(true);   // iterate forward
  const i1 = BattleManager.actor().index(); // get current index of new inputting actor
  $gameParty.swapOrder(i0, i1);             // re-order party
  SceneManager._scene._statusWindow.preparePartyRefresh();  // refresh status window
}
Similarly for "swap with previous actor". Seemed to work OK for me with a quick test. That way, members who can choose actions this turn but have yet to do so will get pushed to the back of the party, to avoid skipping them entirely.
AHHHH!!! preparePartyRefresh works wonders! Thanks!

Curiously enough $gameParty.members() returns the same amount of actors as $gameParty.battleMembers(), so replacing battleMembers() with members() works just the same.

Going to experiment now if allMembers() works in MZ. Edit: it does... so I can now also cycle through members outside of the battle members. Woohoo!

JavaScript:
// Swap with next actor (if present)
let i0 = BattleManager.actor()?.index();
if (i0 >= 0 && $gameParty.allMembers().slice(i0 + 1).some(
  actor => actor.canInput()  // "there is a next actor"
)) {
  BattleManager.changeCurrentActor(true);   // iterate forward
  let i1 = BattleManager.actor().index()
  ; // get current index of new inputting actor
  do {
  $gameParty.swapOrder(i0, i1);             // re-order party
  i0++;
  i1++;
  } while ($gameParty.allMembers().slice(i0 + 1).some(actor => actor.canInput())); // "there is a next actor"
  SceneManager._scene._statusWindow.preparePartyRefresh();  // refresh status window
}
Yay! 😂
Curiously enough $gameParty.members() returns the same amount of actors as $gameParty.battleMembers()
It's not curious, it's explicitly intended.

You can grep the function in the code, it's all of one line in rmmz_objects - it says "if you're in battle, return battleMembers(), otherwise return allMembers()".

So, technically speaking, battleMembers() is more efficient by, like, one operation 😉
But of course, here it is... thanks for clearing that up!

JavaScript:
Game_Party.prototype.members = function() {
    return this.inBattle() ? this.battleMembers() : this.allMembers();

It so far appears to be battlecore-proof as well, so onto the next step: ability to stop input after X number of characters (iow select number of battlemembers at start of each turn).

Original thread: https://forums.rpgmakerweb.com/threads/swap-out-characters-during-command-input.163802/