Check if any troops are affected by state

Hello devs. I hope the new year has been treating you all well.

TL;DR: I need a conditional branch script that can check if any alive troops within the battle are affected by a certain state - I'm using one from a JS notetag, but it always returns positive even when it shouldn't. The branch is used in a visustella Battlecore action sequence and also in troop events.

I've included a screenshot of the script for context:

$gameTroop.aliveMembers().filter(troop => troop.isStateAffected(41));


1677052727754.png


Background:

I'm developing a skill for an eldritch themed summon (picture a mass of tentacles) that grapples and constricts enemies. The core functions of the skill work reliably - I've detailed them below.

Tendril Assault Function:

This skill targets a single enemy, deals moderate damage and then adds a state "Grappled" to the target. It also adds a "Grappling" state to the summon. This is done via action sequence.

The grappled state includes the <Provoke> note tag to force the target to focus all attacks on the summon. The "Grappling" state received by the summon replaces its attack skill with "Constrict tendril" which will deal damage to any entity with the "Grappled" state. This is functioning correctly.

Constrict Tendril Function:

This skill targets all enemies affected by "Grappled" (state ID 41). I found a handy JS notetag script in this wonderful community and modified it:

<JS Targets>
targets=$gameTroop.aliveMembers().filter(troop => troop.isStateAffected(41));
</JS Targets>

This functions correctly.


1677054100874.png

The Problems:

It all comes down to being stuck with ineligible targets.

1. The script in the conditional branch has always returned true even if enemies resist the Grapple.

2. I intend to have enemies that are immune to "Grappled" state - its entirely possible for this ability to not add any grappled states, but the summon will still receive the "Grappling" state and have its attack replaced with Constrict Tendril which won't have any eligible targets.

3. Its also possible, and likely for grappled targets to die from other means, leaving the summon with the Grappling state and no eligible targets for Constrict Tendril once again.

As seen in TL;DR I'm currently trying to find a way to make an event check if any alive troop members are affected by Grappled and therefore eligible - this way I can devise a check to remove the Grappling state from the summon if no enemies with the Grappled state exist. This will likely occur in action sequence and as an end turn troop event.

I'm not 100% married to how this currently functions, but its what I have 'working' for the time being with the exception of the two problems above. I

Any guidance especially with script call syntax/viability for troop checks will be very much appreciated.
This
Code:
$gameTroop.aliveMembers().filter(troop => troop.isStateAffected(41));

returns an array (which may or may not be empty), so you are always going to get a true result.

Change it to this:
Code:
$gameTroop.aliveMembers().some(troop => troop.isStateAffected(41));
Shaz, you're both prompt and wonderful.
Thank you for assisting this ignorant noob.
Would this be different in MV than MZ? It doesn't seem to be working for me in MV.

@GeneralIroh, please refrain from necro-posting in a thread. Necro-posting is posting in a thread that has not had posting activity in over 30 days. You can review our forum rules here. Thank you.


I would suggest you make a new thread in MV Support.

Original thread: https://forums.rpgmakerweb.com/threads/check-if-any-troops-are-affected-by-state.155188/