MZ How to get a party member's highest stat for a variable?

So I'm using custom stats and I use on the conditinoal branch event this on the JS portion "
$gameParty.members().some((member) => member.chr > 5);" which works great. The party member with the highest "chr" stat gets used so any hitting chr over 5 fires up the event. However how would I go around putting this into a variable?
I've tried "$gameParty.members().some((member) => member.chr" in the JS portion of the variable event command but it doesn't work.
JavaScript:
const members = $gameParty.movableMembers(); const bestChr = Math.max(...members.map(member => member.chr); members.find(member => member.chr === bestChr)

would give you the party member with the highest chr stat.
It doesn't work because some() returns true or false.


Setting a variable to true doesn't have anything to do with the operation you're performing inside the function.

Also, this is not technically correct:
The party member with the highest "chr" stat gets used
What you typed will simply be true as soon as it sees any actor with a chr over 5. It has no idea what the highest is and the highest is not used.

You could do this:
Code:
let value =0; $gameParty.members().forEach(actor => value = Math.max(value, actor.chr)); value;

The variable will have the highest chr value, then you simply use a conditional branch to see if it's higher than 5.
If you want the actual highest chr value, it would be better to do

JavaScript:
Math.max(...$gameParty.movableMembers().map(member => member.chr))

(movableMembers makes more sense because ones who are currently restricted would logically be unable to participate in such tests of character)
(movableMembers makes more sense because ones who are currently restricted would logically be unable to participate in such tests of character)
Isn't that making the assumption that this is happening in battle?

Or am I missing something?

Edit: I suppose everyone will pass canMove() out of battle, so it doesn't make a difference there.
Alright, thanks for the responses!
Isn't that making the assumption that this is happening in battle?

Or am I missing something?

Edit: I suppose everyone will pass canMove() out of battle, so it doesn't make a difference there.
What I didn't want to assume was that OP didn't have any restrict states that persisted outside of combat, like Petrify.
What I didn't want to assume was that OP didn't have any restrict states that persisted outside of combat, like Petrify.
Sounds like you're assuming a Petrified actor wouldn't be charismatic!

I know a number of people who would be more charming if they couldn't emote.

Original thread: https://forums.rpgmakerweb.com/threads/how-to-get-a-party-members-highest-stat-for-a-variable.164477/