RPGMaker MV Change Party Member Order via Event

How can I programmatically change the order of my party members from an event, when I pick up a new party member.


My party has 3 members, and instead of my new party member taking the 4th slot, I want to programatically swap him out with the second party member so that the second party member takes the 4th slot, and the new party member takes the 2nd slot. 


I believe this can be done in VX using the following command:


$game_party.swap(1, $game_actors[3].index)



However, when I try and execute this script in RPGMaker MV to swap the position of party members, I get the error shown in the screen shot below.


If there is a different way to programmatically swap party member positions, that's fine too, I just need to know what the command or process is to do it programatically.


Screen Shot 2016-06-18 at 2.58.46 PM.png
Hi!


Try this to change the order of the party.


$gameParty.swapOrder(index1,index2)


To return the position of an actor in the party you can try:


$gameParty.members().indexOf($gameActors.actor(index))


So as an example, to make actor 2 the party leader:


$gameParty.swapOrder(0,$gameParty.members().indexOf($gameActors.actor(2)))


Or to swap actor 2 and 4 places:

Code:
var a, b
a = $gameParty.members().indexOf($gameActors.actor(2));
b = $gameParty.members().indexOf($gameActors.actor(4));
$gameParty.swapOrder(a, b)
Can you remove everyone from the party, then put them in the order you want? That's what I've been doing in ACE to force things into certain orders, and it works fine there, and I imagine it should work in MV as well.
Thanks Astfgl66 that's exactly what I was looking for!


bgillisp, I actually used your method an hour ago to get around my immediate roadblock. It works great for the specific road block I needed to get around today, but later on in my game, there are certain things I will be doing that require me to code it and track party members, positions and locations. So Astfgl66's answer is what I was really looking for.


However, I will use your suggestion (as I discovered) for the simple stuff where I don't need to track positions and react dynamically to various changes in party formation the game player may perform themselves. 
I've tried using

$gameParty.swapOrder(1, $gameParty.members().indexOf($gameActors.actor(2)));

to place actor 2 on party position 2.

My game stops running without the party members (completely) being switched out.

I tested the script in the troops tab of the database and I've tried using the integrated battle test function:

Database.png

Here's the party configuration before starting the battle:

actor1.png actor2.png actor3.png actor4.png

This is where the the game stops running (right at the beginning of the battle):

In-Battle.png

Actor 2 ("Milana") should be placed on party member position 2. In this case I'd like Agios to switch with Milana.

But, what happened here is:
Actor 1 ("Extro") was being pushed to party member position 2, position 1 is now empty. Agios just disappeared. Somehow the enemy already started using the first skill, which I do not understand and then it just stops.

Venex, please refrain from necro-posting in a thread. Necro-posting is posting in a thread that has not had posting activity in over 30 days. You can review our forum rules here. Thank you.


Please create a new thread, as this one is over a year old, and there is no guarantee that anyone on this thread will see this and be able to help.

Original thread: https://forums.rpgmakerweb.com/threads/rpgmaker-mv-change-party-member-order-via-event.63787/