MV Changing a variable to count states on an enemy (involves Yanfly's Skill Core)

So I'm trying to make an attack that deals extra damage depending on how many states an enemy has on them, and to that end I wrote the following bit of code using Skill Core's <Before Eval> notetag:

Code:
<Before Eval>
var commonStates = [4, 5, 6, 7, 8, 9, 10, 48];
var targetStates = target.states();
var damageMult = 1;
for (let a = 0; a < targetStates.length; a++) {
if commonStates.contains(targetStates[a]) {
damageMult += .25;
}
}
$gameVariables.setValue(70, damageMult);
</Before Eval>

However, this doesn't seem to have any effect at all when I hook variable 70 into the skill's damage formula as a multiplier. As far as I can tell from debugging, targetStates is never getting a value, but this doesn't make sense to me, as some of Yanfly's tutorials use this exact method. Can anyone tell me what I'm doing wrong here?
So I'm trying to make an attack that deals extra damage depending on how many states an enemy has on them, and to that end I wrote the following bit of code using Skill Core's <Before Eval> notetag:

Code:
<Before Eval>
var commonStates = [4, 5, 6, 7, 8, 9, 10, 48];
var targetStates = target.states();
var damageMult = 1;
for (let a = 0; a < targetStates.length; a++) {
if commonStates.contains(targetStates[a]) {
damageMult += .25;
}
}
$gameVariables.setValue(70, damageMult);
</Before Eval>

However, this doesn't seem to have any effect at all when I hook variable 70 into the skill's damage formula as a multiplier. As far as I can tell from debugging, targetStates is never getting a value, but this doesn't make sense to me, as some of Yanfly's tutorials use this exact method. Can anyone tell me what I'm doing wrong here?
Hello @caseorogue . Can you try the code below?
JavaScript:
<Before Eval>
var commonStates = [4, 5, 6, 7, 8, 9, 10, 48];
var targetStates = target.states();
var damageMult = 1;
for (var a = 0; a < targetStates.length; a++) {
  if (commonStates.contains(targetStates[a])) {
    damageMult += 0.25;
  }
}
damageMult *= 100;
$gameVariables.setValue(70, damageMult);
</Before Eval>
Then in your damage formula you divide Variable 70 (or v[70] or $gameVariables.value(70)) by 100 (or multiply by 0.01).
Spoiler: Code Explanation
  • This is just an oversight on your end but you missed a set of parenthesis in your conditional i.e. if commonStates.contains(targetStates[a]).
  • For consistency I used var when declaring the i counter variable since you mentioned Yanfly. Your using let is still fine though. 👋
  • You may want to make your code as readable as possible so you can easily detect potential errors. So I added the indents as well as the zero in front of the decimal point.
  • The main change in the code is multiplying damageMult by 100 to turn it into a whole number and then adjusting the value of Variable 70 in your damage formula by dividing the latter by 100. The reason is because when you use $gameVariables.setValue(variableId, value) if value is a primitive data type of 'number' (just think of it as your usual number), value is ROUNDED DOWN.
Your damage code is pretty neat though. I hope you don't mind me "borrowing" your idea, would you? 😊
Ah, I completely missed the dropped parentheses. That may have been what was causing the issue.

You're welcome to use the idea if you like, though! Your tips were appreciated and it's the least I can do for the help.
By the way @caseorogue, since you're using YEP Skill Core you can use the following code instead if you want. You no longer need to use Variable 70 in this case.
JavaScript:
<Pre-Damage Eval>
var commonStates = [4, 5, 6, 7, 8, 9, 10, 48];
var targetStates = target.states();
var damageMult = 1;
for (var a = 0; a < targetStates.length; a++) {
  if (commonStates.contains(targetStates[a])) {
    damageMult += 0.25;
  }
}
value *= damageMult;
</Pre-Damage Eval>
By the way @caseorogue, since you're using YEP Skill Core you can use the following code instead if you want. You no longer need to use Variable 70 in this case.
JavaScript:
<Pre-Damage Eval>
var commonStates = [4, 5, 6, 7, 8, 9, 10, 48];
var targetStates = target.states();
var damageMult = 1;
for (var a = 0; a < targetStates.length; a++) {
  if (commonStates.contains(targetStates[a])) {
    damageMult += 0.25;
  }
}
value *= damageMult;
</Pre-Damage Eval>
Fair point! I hadn't considered using the value multiplier, but it may be a good way to simplify the code.

Original thread: https://forums.rpgmakerweb.com/threads/changing-a-variable-to-count-states-on-an-enemy-involves-yanflys-skill-core.146838/