Help with party script call

Hello, and thanks in advance.

I have searched the interwebs high and low for answers and I have come up short, it seems. What I am attempting to do is display a function (e.g. HP gauge, etc.) via SRD HUDmaker if a player occupies a particular spot in the formation. For example, for the condition of the typically 4th slot player occupying the 3rd slot, I have been trying:

$gameParty.members()[2].actorId(4) == 4 && $gameParty.members().length < 4

or

$gameParty.members()[2].actorId(4) == 4 && $gameParty.members().length == 3

or

$gameParty.members()[2].actorId() == 4 && $gameParty.members().length < 4

or

$gameParty.members()[2].actorId() == 4 && $gameParty.members().length == 3


to no avail receiving "TypeError: Cannot read property 'actorId' of undefined" in the console (when I press F8). Can anyone help me figure out what I'm doing incorrectly here? Thanks again!
Judging from the error message alone, it means $gameParty.members()[2] isnt returning an object

$gameParty.members()[2] should be returning the 3rd member iirc since the leader is in index 0

unless you don't have a 3rd party member, it shouldn't be giving that error afaik
I was hoping to check that actor Id 04 was the 3rd member, but I don't think I'm doing it correctly.
I tested this part via using it as a condition for something random

$gameParty.members()[2].actorId() == 4

and it seems to work fine for me for testing purposes.. so at least the .members()[2] call shouldnt be a problem and the condition should be fine too

Given the error message, the plugin might be initializing this HUD effect of yours before the party is initialized, resulting to the members()[2] giving an undefined object instead.. Sadly I'm not versed in that plugin so I'm not sure how it starts the custom HUDs
You are correct. I had a scene prior to initialization of the party that apparently was causing all the headache. If I want to keep my HUD, I'll have to consider another approach. Thank you so much for your time and effort in helping me sort this out!!
can't you just disable that HUD first until the party is done?

or you could also opt to add a higher condition first, like check first if $gameParty.members()[2] is defined or not, if it is, then you proceed with your party member check.. or does the HUD Maker doesn't allow that?
Well the HUD Maker allows one spot for a conditional statement. As far as I can tell, I am able to do and/or conditions. It really was a minor change to make, starting with the party, as that is the intention anyway. Formerly, the party joined after a short walking and dialogue scene. I've just combined them in a way that I'm satisfied with and satisfies the conditional statement of the HUD Maker, so we're all good. 😎
While this seems unnecessary as you have already found a solution I just wanted to add the following for future reference:
In all programming languages I know of conditional statements are evaluated in order. With the && operand the statements will only be evaluated until the first one returns false (since a single false value causes the whole boolean 'and'-expression to become false).
The inverse is the case for the || operand. Since a single true value causes the whole expression to be true, no statements will be evaluated after the first one returned true.

This is the problem with your initial statements: javascript first tries to check the actorId of the third actor (and already fails in this step as the actor is not in the party yet). Only if this check would return true it would then proceed to check whether the party is actually long enough to contain 3 actors.
If you simply reverse the order of the statements in your condition your initial attempt should work.
JavaScript:
$gameParty.members().length >= 3  && $gameParty.members()[2].actorId() == 4
Now it first checks if the Party has at least 3 members and only if that is the case it will check the actorId of the third actor.

Lastly a bonus bit of information: if object will return false if object is undefined. So you could also write:
JavaScript:
$gameParty.members()[2] && $gameParty.members()[2].actorId() == 4
While this seems unnecessary as you have already found a solution I just wanted to add the following for future reference:
In all programming languages I know of conditional statements are evaluated in order. With the && operand the statements will only be evaluated until the first one returns false (since a single false value causes the whole boolean 'and'-expression to become false).
The inverse is the case for the || operand. Since a single true value causes the whole expression to be true, no statements will be evaluated after the first one returned true.

This is the problem with your initial statements: javascript first tries to check the actorId of the third actor (and already fails in this step as the actor is not in the party yet). Only if this check would return true it would then proceed to check whether the party is actually long enough to contain 3 actors.
If you simply reverse the order of the statements in your condition your initial attempt should work.
JavaScript:
$gameParty.members().length >= 3 && $gameParty.members()[2].actorId() == 4
Now it first checks if the Party has at least 3 members and only if that is the case it will check the actorId of the third actor.

Lastly a bonus bit of information: if object will return false if object is undefined. So you could also write:
JavaScript:
$gameParty.members()[2] && $gameParty.members()[2].actorId() == 4
Thank you so much for this reply, it is very insightful and will help me as I continue with my game!

Original thread: https://forums.rpgmakerweb.com/threads/help-with-party-script-call.142226/