Variable-dependent damage

Hey all. I'm trying to set up yet another custom damage formula for one of the character skills.

What I want to do with this one is make it so that a normally weak attack will deal massive damage with every 5 uses. My plan is that so every time the skill is used, variable 10 goes up by 1, and when it's at 5, it deals the big damage and brings the variable back down to 0.

The weak damage is successfully being dealt, but for some reason, the big damage never comes around.

I have the formula set up like this:

if (v[10] === 5) {v[10] -= 5; a.mat * 25} else {v[10] += 1; a.mat * 2}

For testing purposes, I decided to make the skill run a common event that increases the variable, and then the big damage occurs, but through the common event, it occurs every 4 uses instead of 5. I want to increase the variable through the formula because I plan to make stored uses carry over to subsequent fights, potentially giving the chance for the player to start a boss fight with big damage, for example. Using a common event for this is an issue because, if the skill is the last one used in a fight, running the common event might not work fully as intended.
When using $gameVariables._data (in this case, the variable v) to assign value to a variable, you must establish that that variable is a number since by default, the variables are undefined, not 0. Using $gameVariables.value(10) will give you 0 since the function checks if there is a value:
JavaScript:
Game_Variables.prototype.value = function(variableId) {
    return this._data[variableId] || 0;
};
If not, it returns 0.

This means that v[10] += 1 doesn't do anything since you cannot add 1 to an undefined variable (causing it to return NaN or Not a Number). You could assign the variable to 0 before the battle begins, or try this:
JavaScript:
!v[10] ? v[10] = 0 : v[10]; v[10] === 5 ? (v[10] = 0, a.mat * 25) : (v[10] += 1, a.mat * 2)

If you assigned variable 10 to the value 0 before the battle, you can just use this:
JavaScript:
v[10] === 5 ? (v[10] = 0, a.mat * 25) : (v[10] += 1, a.mat * 2)

You may consider setting it to 0 at the end of the battle as well, otherwise, it will accumulate between battles (unless that is what you want).
Oooh, I didn't realize that the variable had to be set to a number before the fight.

I decided to run with the last formula to make things simpler, and set the variable 10 to 0 at the start of the game.

Also, I have noticed that since the variable starts at 0, and increases by 1 after every use of the skill, it will only reach 5 after five uses, making it so that the big damage occurs on the sixth use, so I made the big damage happen when the variable is 4 instead.

And yes, I do plan on making it accumulate between battles, so that's fine.

Thank you for the help.
I don't know what else is happening in your common event, but I don't immediately see why you're both manipulating the variable in the damage formula and again in a common event after the skill is done.

Why isn't everything in one place?
I already got it figured out. My guess is that since the common event had set the variable value, the formula was working as it should and increasing the value alongside the common event. I've already removed the latter and have only the formula going now.

Original thread: https://forums.rpgmakerweb.com/threads/variable-dependent-damage.170903/