Party member attack to variable issue

Hi, im having a small issue with the map based battle system i'm making. i cannot set a variable of the ATK of a party member. here's a screenshot of the section of the event and the respective error atributed to it:
Spoiler: Images
e45c6e00defcceebb7a9a1ceb4d64f01.png
41a3ace9b529b735f45f4136ea4ec2f1.png

any help is appreciated, as i haven't been able to find a solution to this yet.
How many members are in the party when that error happens? My guess is that you have less than 3 party members.

To find out, when the error happens, open the console by pressing F8.
Type this and press enter:
Code:
$gameParty.members();
Then you can check how many, and can expand the results to see more details.
ah, that'd make sense, let me try something for a second

EDIT: yes, that was the issue.
24f4ad27dbb1c620112fffdf28106d32.png

do you know how to check the size of the party then? some things are dependent on how many you have in your party, i'll have to create a conditional branch
You'll probably want to do that with a loop anyway, its both cleaner and more efficient and will save you party size checks.
Something like that should work
Code:
var members =$gameParty.members()
for (var i = 0; i < members.length; i++) { //loop through all members
 $gameVariables.setValue(69 + i, members[i].atk) //set variable 69 to party member 1 attack, 70 pm 2, 71 pm 3
}

You can add lines to that loop to store defense or anything else really, just change the default variable number.

To check party size just type:
$gameParty.members().length
You'll probably want to do that with a loop anyway, its both cleaner and more efficient and will save you party size checks.
Something like that should work
Code:
var members =$gameParty.members()
for (var i = 0; i < members.length; i++) { //loop through all members
 $gameVariables.setValue(69 + i, members[i].atk) //set variable 69 to party member 1 attack, 70 pm 2, 71 pm 3
}

You can add lines to that loop to store defense or anything else really, just change the default variable number.

To check party size just type:
$gameParty.members().length

thanks, although i only need to check it once at the beginning of the event. (due to it being just an event that runs once to set up variables needed for calculations) $gameParty.members() was the correct script call needed. (not sure 100% how to mention someone) but thanks @Aloe Guvner for helping out with this as well. the thread can be closed thanks to the issue being resolved.
thanks, although i only need to check it once at the beginning of the event.
Actually, @Astfgl66 suggestion is exactly this. You could try his/her suggestion in a Script Call Event Command, because you then you don't need to worry about how many members are in the party. It will figure that out for you.

For example, in your screenshot, you might have 1 or 2 or 3 members in the party.

What his/her code is doing:
  • Set Variable #69 to the first member attack
  • Set Variable #70 to the second member attack (if there is a second member!)
  • Set Variable #71 to the third member attack (if there is a third member!)

Spoiler: Another way to write it
This is exactly the same as the suggestion, just written more concisely:
Code:
$gameParty.members.forEach(function(actor, i){$gameVariables.setValue(69 + i, actor.atk);});
$gameParty.members.forEach(function(actor, i){$gameVariables.setValue(73 + i, actor.def);});

Original thread: https://forums.rpgmakerweb.com/threads/party-member-attack-to-variable-issue.95266/