MZ Having problems with Notetags

I'm making a character wich skill consists in a Parry that makes "Alexander enters in the "Stand" state for three turns. Stand: Alexander can't move and will reduce all damage up to 200% of his DEF (damage will stack). When Alexander takes damage, "Stand" will break, dealing 100% of Alexander's DEF as damage to all opponents."

For this I'm using visustella free plugins and this:

Code:
<JS On Add State>
var standGauge = target.def*2;
</JS On Add State>

<JS Pre-Damage as Target>
    if (value > 0 && this.isHpEffect()) {
        damage = value;
        value -= standGauge;
        standGauge -= damage;
        if (standGauge =< 0) {
            target.removeState(79);
        }
    }
</JS Pre-Damage as Target>

<JS On Expire State>
    target.dmgAccum = 0;
</JS On Expire State>

but it doesn't works, and I still doesn't know how to make the "dealing 100% of Alexander's DEF as damage to all opponents." part.
but it doesn't works
You always need to be more specific - what doesn't work? Does it do nothing different? Does it do something that you don't want it to? Does it crash the game? It's very difficult for someone to fix a problem if they don't know what it is 😉

However, I can see you have a number of weird things going on here. One big problem: you're declaring this standGauge variable inside one notetag then trying to use it in another.

That can never work, because as soon as your first notetag is done being evaluated that variable goes away.

That's the whole point of putting variables attached to the battlers - and you do this correctly when you reference target.dmgAccum (more on that later), but for some reason you do it differently with standGauge.

You can fix it by making it into something like target.standGauge. You still don't need to initialize it in a separate notetag, there's a neat little tweak of JavaScript that you see in a ton of the Yanfly Tip & Tricks: target.standGauge = target.standGauge || target.def*2;

That means if standGauge already has a value, keep it, otherwise initialize it to def*2.

So, a few other things:
Code:
        damage = value;
        value -= standGauge;
        standGauge -= damage;
There are a few problems here. One, you don't declare damage which means it's a global variable. Use var or let. Two, I don't think your logic is doing what you want. Why are you subtracting the current standGauge from the incoming damage? Why are you making this variable at all?

You don't actually say how much you want the damage reduced by - is it completely negated, and he doesn't take any damage until he's absorbed 200% of his Def? If that's the case, your code should simply say:
Code:
target.standGauge-=value;
value=0;

I don't see what you're trying to accomplish with this extra "damage" variable.

Code:
        if (standGauge =< 0) {
This is invalid syntax (both coding and mathematically 😉). It's <= or >=, the greater/lesser than always comes first.

Code:
<JS On Expire State>
    target.dmgAccum = 0;
</JS On Expire State>
It's a little bit cleaner to actually remove extra variables when you're done using them, that way they don't get stuck into the save file. It's an insignificant amount of bloat, in most cases, but it's a good habit. So you'd do:
Code:
delete target.dmgAccum;
delete target.standGauge;

But also...what the heck is this? Where did dmgAccum come from? You never reference it anyplace else. If it's related to something else in your game that doesn't have anything to do with your Stand ability, you don't need to include it in this post.

You want to put the variables cleanup into JS On Erase State, not Expire, so that they get cleaned up when the state is removed in all ways, not just from it timing out.

, and I still doesn't know how to make the "dealing 100% of Alexander's DEF as damage to all opponents." part.
Code:
$gameTroop.aliveMembers().forEach(enemy => enemy.gainHp(0-target.def));

You may also need to call the damage popup, depending on what you want and such.
what doesn't work?
It doesn't reduce any damage.
Why aren't you actually modifying "value" when you said you want "Alexander can't move and will reduce all damage"?
This was a writting error, it should be "Alexander can't move and will reduce the upcoming damage up to the 200% of his DEF" (for example if the attack does 200, and the 200% of his DEF is 100, he will receive 100 of damage).

I don't see what you're trying to accomplish with this extra "damage" variable.
it's for save the value before the standGauge is subtracted.
Where did dmgAccum come from?
That was because I'm a lazy idiot that, instead of make all the code, I copy a skill that should inflict damage instead, changed some var names but not all.

Thanks for all the help, I will try to fix it.
Now it says: "
SyntaxError
Identifier 'target' has already been declared"

--Solved--
I just deleted the var and let.
Just as a reminder, we're not supposed to double post.

I just deleted the var and let.
Yes, when you're putting a variable into an existing object, like the battler "target," you do not declare it.

This was a writting error, it should be "Alexander can't move and will reduce the upcoming damage up to the 200% of his DEF" (for example if the attack does 200, and the 200% of his DEF is 100, he will receive 100 of damage).
Okay. I'm still not sure this is doing what you want (or if it's a problem with wording it correctly in English).

You're subtracting from standGauge every hit, which means it's going to reduce less and less damage until it's gone. I would expect from your description that every hit is going to be reduced by 200% of Def.

If that's correct, you need to use another variable to track how much damage has been absorbed and don't touch standGauge once you've declared it.
You're subtracting from standGauge every hit, which means it's going to reduce less and less damage until it's gone.
Yeah, that's what I was trying to do, like a shield.

Original thread: https://forums.rpgmakerweb.com/threads/having-problems-with-notetags.153400/