MZ [Resolved(??)] Script for swapping formation of (multiple) party members? (MZ)

So, I have read this previous thread on changing the party order.
If I use:
JavaScript:
$gameParty.swapOrder(0, 1);
It sucessfully swaps party members A and B. Yay!

So what is the problem you ask?
Well, if I have 3 party members, member 3 remains forever forgotten. 🙁
(And if I have only 2, "$gameParty.swapOrder(2, 1);" breaks everything!)

I attempted to fix this myself using:
JavaScript:
if ($gameParty.members().length == 3) {
   $gameParty.swapOrder(0, 1)
   $gameParty.swapOrder(2, 1);
}
else if ($gameParty.members().length == 2) {
   $gameParty.swapOrder(0, 1);
}
else {
}
To check the number of party members, and then swap the formation accordingly.

Which works!... in MV.
Now that I have moved my project over to MZ, it suddenly does not.

I'm not sure what is not working here. I know it's not the SwapOrder itself, so it must either be the if/else branch or the $gameParty.members().length query?
I'm a complete Javascript newby so I've probably just messed something up. 😅

If anyone has any suggestions, I will be all ears!
When you say that it doesn't work, what is not working ? What do you want to achieve exactly ?

I tested with 3 actor in the party, with the code you give here :

JavaScript:
if ($gameParty.members().length == 3) {
   $gameParty.swapOrder(0, 1)
   $gameParty.swapOrder(2, 1);
}
else if ($gameParty.members().length == 2) {
   $gameParty.swapOrder(0, 1);
}

And everything works. Don't hesitate to show how you use this Javascript code 😀
Ah, thanks @Kono!

I'm trying to use a Common Event with this script in conjunction with VisuStella's Button Common Event Plugin to allow the player to cycle between the party members on the fly.
I'm using an ABS battle system, JABS, but only want one party member fighting at a time, as I feel it gets a bit too chaotic with more than one.

So, I have the common event with this script bound to 'A':
JavaScript:
$gameParty.swapOrder(0, 1)
Which successfully swaps my 1st and second members when I hit it!

However, if I have 3 members, the third member is not cycled, and if I have only 1, I get a crash since there's no party member in position 1 to swap with.

Using the exact same setup with the 'A' key but bound to a common event with this script:
JavaScript:
if ($gameParty.members().length == 3) {
   $gameParty.swapOrder(0, 1)
   $gameParty.swapOrder(2, 1);
}
else if ($gameParty.members().length == 2) {
   $gameParty.swapOrder(0, 1);
}

However, when I hit 'A' with the If/else script and two party members, no swapping happens. (The button lights up, and if I put an SE in the event, that does play - so just no formation change script function). No errors show up in the Console, either using VisuStella's Debug Console).

If I have three party members, the same thing happens. The Common Event is being called successfully, but no swapping. It's as if the whole Script is being ignored.

I've uploaded a bunch of images ad gifs below, so hopefully that makes it more clear!
I'm really not sure what's gone wrong here, since as you said, the script itself seems ok? 😮

Spoiler: Image and GIF Examples
The VisuStella Plugin:
1635630314674.png


The Common Event:
1635630239640.png


In-Game:
Swapping using just the single-line script and 1 party member:

error1.gif

I don't want to allow swapping if only 1 member.

Swapping with 3:
error 2.gif

No cycling!


With the extended If/Else Script:
Any variation of party members:
Nothing happens re formation changes. WAIT. WHAT. IT'S WORKING NOW?! :kaomad2:
ezgif-7-ba245059adb8.gif



Annndddd... as any problem is wont to do, the second I took the time to actually document the bug properly it... stopped happening?
So SUDDENLY the if/else common event script works just fine, and is cycling between party members as required... I'm so confused as to why it was not functioning before but is now.
Maybe because I'm on a different PC? (Since I move between my desktop and laptop) What?

Um, thank you for your help! I'll ask this to be closed, now. Sorry about that!
(But I'm leaving this post with all my pretty GIFs and explanations because they took forever 😠)
(And may be... amusing for someone one day)
Thread closed

Original thread: https://forums.rpgmakerweb.com/threads/resolved-script-for-swapping-formation-of-multiple-party-members-mz.141669/