Forcing targets with states, VisuStella Action Sequence

I have two skills at play, where one skill "forecasts" the target of the second. The skills are:

  1. Deliberation - Add "Judged" state to random opponent
  2. Judgment - Attack "Judged" enemy
I am using VisuStella's CoreEngine and BattleCore, but I can't quite work out the best way to do this. I am struggling to understand exactly how targeting works, and how to interact with manual JS targetting or action sequence targetting.

For example, I tried setting a variable 'judgementTarget' when the state is added, then setting the target to that variable, but I ultimately got an error that 'judgmentTarget' was undefined (see console screenshot).

Spoiler: State
ManualTargetting-JudgeState.png
Spoiler: Skill
ManualTargetting-JudgementSkill.png
Spoiler: Console
ManualTargetting-Console.png


I also thought I could:
  1. Set 'Judgment' to attack all targets
  2. Using a custom action sequence to only apply the action effects to targets with the state
However, I couldn't figure out how to do #2 in that step, since I don't quite understand target. The check I try in the screenshot fails for every target in the index.

Spoiler: Common Event - 'Judgment' Action Sequence
ManualTargetting-ActSeq.png

I should think there would be an even simpler method, but I can't work it out. Is there a good best practice for doing this?

I'm open to not doing the two-skill setup as well. I just want to telegraph this 'execution' style attack so the player can guard with and/or cast a heal on the victim.
I worked this out with some help from NaosoX on the VS Discord. Here is my solution for interested parties.

This uses the VS BattleCore Javascript notetags; I am targetting entirely within the skills themselves rather than action sequences or using the state.

Skill A (enemy designates the target to the player):
Code:
<JS Post-Apply>
  $gameVariables.setValue(x, target.index());
</JS Post-Apply>

Skill B (enemy attacks the designated target):
Code:
<JS Targets>
  targets = $gameParty.aliveMembers().filter((member, index) => index == $gameVariables.value(x)); 
</JS Targets>
I don't know the exact circumstances and timing of your skills, but there is room for error in the way you have it.

When you call the index() method of a battler, it returns their index within their unit - e.g. $gameParty.members() or $gameTroop.members()

If there are any dead battlers in that unit, their index may not necessarily be the same if you reference aliveMembers().

For example, if you're targeting the fourth actor in the battle party, and the second actor is dead, their index() will still return 3. However, their index in aliveMembers() is 2.

You could get around that by replacing target.index() with $gameParty.aliveMembers().indexOf(target)

However, that still has room for error if it is possible for:
1 - enemy uses Deliberation
2 - another enemy does something that causes damage, which could kill a party member and cause the indices to change
3 - an enemy uses Judgment and the index is now different (or out of bounds)

I think a better solution is to either:
1 - make Judged a state, as in your original post. Then your targets filter is
Code:
targets = $gameParty.aliveMembers().filter(member => member.isStateAffected(x));
where x is the ID of your Judgment state.
or
2 - if you prefer the variables route for some reason, store something actually specific to the target, such as its ID or name. So you could do in the Post-Apply:
Code:
$gameVariables.setValue(x, target.actorId());
then your targets filter is:
Code:
targets = $gameParty.aliveMembers().filter(member => member.actorId() == $gameVariables.value(x));
These are more elegant solutions. Thank you!

Original thread: https://forums.rpgmakerweb.com/threads/forcing-targets-with-states-visustella-action-sequence.151861/