store party members actor id's in variables

Hello all,

I'm trying to store the party members ID if they are affected by a certain state but for whatever reason, this common event script is not working. This common event is called right after a battle is over. Did I miss something here?

var gameVars = 129;

for(var i = 0; $gameParty.members().length < i; i++)
{
If($gameParty.members().isStateAffected(63))
{
$gameVariables.setValue(gameVars,$gameParty.members().actorId());
}

gameVars++;
}
You didn't specify which party member when checking if he/she is affected by state 63 (you really have 63 states? wow):

Code:
if ($gameParty.members().isStateAffected(63))

// Needs to be member [i]:
if ($gameParty.members()[i].isStateAffected(63))
Also

Code:
for(var i = 0; $gameParty.members().length < i; i++)

$gameParty.members().length will never be less than 0.

Code:
for(var i=0; i < $gameParty.members().length; i++)

You are also incrementing your gameVars variable even if the party member is not affected by that state. Are you resetting them all to 0 at any point? If not, you could have member 1 affected by the state in the first battle, so variable 129 will have member 1's id, then in the second battle member 3 might be affected by the state so variable 131 will have member 3's id, but variable 129 will still have member 1's id even though they may not have the state anymore.

And if the player changes the formation between battles and member 1, who had the state after the first battle also has the state after the second battle but is now member 2, you'll have two variables with member 1's actor id.

If you reset all the variables, it means you'll have gaps where some have actor ids and some have 0. Is that what you want?

You may need to explain what you're doing with these variables if you need help to clean up the logic any further.
Ohh yeah, totally went over my head lol ^
lol

Let's say your lineup is actors 1, 2, 3 and 4 in that order.
At the start of the game, variables 129, 130, 131 and 132 will all be 0.

After first battle, actors 1 and 4 have the state.
Variables will be: 129 = 1, 130 = 0, 131 = 0, 132 = 4.

After second battle, actor 2 has the state but nobody else does.
Variables will be: 129 = 1, 130 = 2, 131 = 0, 132 = 4 if there is nothing to reset them between battles.

Player changes formation, so lineup is now 3, 2, 1 and 4 in that order.
After third battle, actor 1 has the state again but nobody else does.
If there is nothing resetting the variables, they will be: 129 = 1, 130 = 2, 131 = 1, 132 = 4
ah, I see lol this is very informational! I do not have 63 states lol I group them and space them out in the list. I will need to reset them before the next fight so maybe just set the vars back to 0 before every battle? I'm using Yanflys base troop events to run some code during each fight so I could set them to 0 there I believe. I'll do some test and get back to you guys, but I guess that explains why I was not getting any errors in the console which threw me off. Thank you very much!
Just set the vars back to 0 at the beginning of your common event.

Original thread: https://forums.rpgmakerweb.com/threads/store-party-members-actor-ids-in-variables.105116/