Hmm, maybe better use "let" instead "const", because const declaration won't allow you to change variable value.
The code you wrote above, the "secondMemberID" is in fact third member too, because you set partySlot value to 3.
Spoiler
JavaScript:
let leaderID = $gameParty.leader().actorId();
let partySize = $gameParty.size();
let partySlot = 2;
let secondMemberID = $gameParty.members()[partySlot-1]?.actorId() || 0;
partySlot = 3; //partySlot is already declared, here we assign new value to it.
let thirdMemberID = $gameParty.members()[partySlot-1]?.actorId() || 0;
return leaderID === 1 && partySize === 3 && secondMemberID === 2 && thirdMemberID === 3;
It can be written shorter, with less variables, I simply tried to make it more readable.
For shorter version:
Spoiler
JavaScript:
let leaderID = $gameParty.leader().actorId();
let partySize = $gameParty.size();
let secondMemberID = $gameParty.members()[1]?.actorId() || 0;
let thirdMemberID = $gameParty.members()[2]?.actorId() || 0;
return leaderID === 1 && partySize === 3 && secondMemberID === 2 && thirdMemberID === 3;
If doing it this way, only need to remember the index of party member is with one less than its actual position, so 4 th member is index 3, and leader is index 0.
Hope didn't do typo on my coding, as this time I wrote it directly on the reply box, without testing it.
The code can be optimized further, actually.
Spoiler
JavaScript:
if ($gameParty.leader().actorId() !== 1) return false; //leader not ID 1
if ($gameParty.size() !== 3) return false;// party size different than 3;
if (($gameParty.members()[1]?.actorId() || 0) !== 2) return false; //second member id not 2
if (($gameParty.members()[2]?.actorId() || 0) !== 3) return false; //third member id not 3
return true;//meets all criteria, return true (which shows the HUD component).
Or even further:
Spoiler
JavaScript:
return (
$gameParty.leader().actorId() === 1 &&
$gameParty.size() === 3 &&
($gameParty.members()[1]?.actorId() || 0) === 2 &&
($gameParty.members()[2]?.actorId() || 0) === 3
);
Since $gameParty.members()[2]?.actorId() gives undefined, if there is no such actor, the check undefined === 3 would be false too, can be writen like that too:
JavaScript:
return (
$gameParty.leader().actorId() === 1 &&
$gameParty.size() === 3 &&
$gameParty.members()[1]?.actorId() === 2 &&
$gameParty.members()[2]?.actorId() === 3
);
What important is, which of those you are most comfortable of using, and would be easier to edit to your liking.