RMMV Brain hurts writing damage script, need help!

I've been writing the Formula for these 2 skills all day, and I hit a block and keep writing the same thing over n over, not knowing why its working.

First skill is meant to save damage as variable, check if enemy, then set new variable of (check max to see which is higher , Damage+ variable, or Damage) Then Deal Damage

Basically I'm stacking Variable 2 to call later.
But its not working.
keeping getting a V not defined error

"Damage Skill"
Code:
Formula:

v[1] = (a.atk + a.mat + a.agi*2) - (b.mdf + b.agi);
console.log(v[1]);

if (b.isEnemy()) v[2] = Math.max(v[1] + v[2], v[1]);
console.log(v[2]);
v[1]

"CALL Variable 2 Skill"
Code:
Formula:
v[3] = (v[2] / 5 ); v[3]
Where are you writing this formula? In the damage formula in the database, or are you using a plugin and putting it in a notetag? Please show a screenshot.


When you get the error, hit F8 and go to the Console tab. Show us a screenshot of that so we can see where the error is being triggered in the code.
Where are you writing this formula? In the damage formula in the database, or are you using a plugin and putting it in a notetag? Please show a screenshot.


When you get the error, hit F8 and go to the Console tab. Show us a screenshot of that so we can see where the error is being triggered in the code.
This is in the "Formula" section of Damage
Both of them are seperate skills
Skill1:
Spoiler
1681016916785.png

Skill2:
Spoiler
1681016938966.png


Console:
Spoiler
1681016990466.png

I'm aware v[2] isnt being set, I just don't know.. why
The error is being thrown by the Game Interpreter Script command - meaning, it's a Script call in an event that's causing the problem, not in any of your damage formulae.

You've got an event somewhere (troop event?) with a script call, where you're trying to use v[n]. v[n] is only valid in damage formulae, not in script calls.
The error is being thrown by the Game Interpreter Script command - meaning, it's a Script call in an event that's causing the problem, not in any of your damage formulae.

You've got an event somewhere (troop event?) with a script call, where you're trying to use v[n]. v[n] is only valid in damage formulae, not in script calls.
Found it, forgot to remove my 'notepad' that had v[1]= 0 and v[2]=0 , However, still unsure why
v[2] in the first damage formula is getting a NaN value

Code:
v[1] = (a.atk + a.mat + a.agi*2) - (b.mdf + b.agi); console.log(v[1]); if (b.isEnemy()) v[2] = Math.max(v[1] + v[2], v[1]); console.log(v[2]); v[1]

The way its written is, v[2] = Highest of (v1 + v2) or ( v1) but its not defining v[2]...
Code:
if (b.isEnemy()) { v[2] = Math.max(v[1] + v[2], v[1]) } ;

{ }

Where are you previously defining v[2]?
Code:
if (b.isEnemy()) { v[2] = Math.max(v[1] + v[2], v[1]) } ;

{ }

Where are you previously defining v[2]?
Brackets isn't working for it.

This is the define location, Similar to v[1] which works as intended. which is defined, right before v[2]

Code:
v[1] = (a.atk + a.mat + a.agi*2) - (b.mdf + b.agi);

v[2] = Math.max(v[1] + v[2], v[1]);

To Better explain what I'm trying to achieve.
Skill damage is defined as v[1]
Each use of the skill stacks and should be defined as v[2] which is the math.max equation

The next skill calls v[2] before resetting v[2] back to 0
But watching console + using the 2nd skill always shows it as NaN value or 0 even after attempting to "stack"

I did not mean to double post this, was suppose to be an edit....
Where you log v[1] to the console, log v[2] as well, just to make sure it IS a number before you get to that part of the formula.

And show where you are previously defining v[2] as the error may be there.

I mean, you need to define v[2] before you use it in this damage formula. If you haven't defined it first, it's going to give you issues. You say the next skill calls (uses?) v[2] before setting it back to 0, but something else needs to set it in the first place, otherwise it's not available to use in the formula above.

When you use $gameVariables.value(2) that calls a function that makes the value default to 0 if it hasn't been previously defined. But when you use v[2] in a damage formula you're bypassing that function and going straight to the data array. So if it hasn't been defined prior to using this skill, you're going to get the 'undefined' value - it's not going to default to 0.

Maybe you just need to do a Control Variables 2 = 0 right at the start of your game.
Where you log v[1] to the console, log v[2] as well, just to make sure it IS a number before you get to that part of the formula.

And show where you are previously defining v[2] as the error may be there.

I mean, you need to define v[2] before you use it in this damage formula. If you haven't defined it first, it's going to give you issues. You say the next skill calls (uses?) v[2] before setting it back to 0, but something else needs to set it in the first place, otherwise it's not available to use in the formula above.

When you use $gameVariables.value(2) that calls a function that makes the value default to 0 if it hasn't been previously defined. But when you use v[2] in a damage formula you're bypassing that function and going straight to the data array. So if it hasn't been defined prior to using this skill, you're going to get the 'undefined' value - it's not going to default to 0.

Maybe you just need to do a Control Variables 2 = 0 right at the start of your game.

I just realized what was happening, using "Battle Test" Doesnt have variables set, so it was throwing NaNs.

Original thread: https://forums.rpgmakerweb.com/threads/rmmv-brain-hurts-writing-damage-script-need-help.156523/