Yanfly's Toxic effect help

Hi, everyone! As part of his tips & tricks series, Yanfly shared a piece of code to replicate the toxic effect from Pokemon. Every turn, the toxic deals more damage to the afflicted.

I would like toxic to be a short status effect of two turns that will keep increasing in damage if reapplied before it expires. In its current form however, the toxic counter is reset to 1 every time the state is reapplied, meaning that is not possible. I tried tinkering with it some, but really falter as this is not my field of expertise. Would anyone know how to accomplish this? Thank you!

Here the code for the regular toxic in question:
<Custom Apply Effect>
this._toxicCounter = 1;
</Custom Apply Effect>

<Custom Regenerate Effect>
var n = this._toxicCounter / 16;
var value = Math.floor(n * user.mhp * -1);
user.gainHp(value);
this._toxicCounter += 1;
</Custom Regenerate Effect>
<Custom Apply Effect>
this._toxicCounter += 1;
</Custom Apply Effect>
Change your apply effect to this and see if it works?

What's happening is that when it's applied, the code is telling it to SET the counter to 1, so if, instead, you do += 1 it'll ADD +1 stack to it, rather than set it back to one.
@Fernyfer775 Thank you for helping me out. Writing it that way, won't the toxic count remain after the status effect left, and once applied later, keep increasing from the value it had? Would we not need to reset the toxic count via a leave effect so that would not be the case?
You are correct. Add this to the end of it:
<Custom Remove Effect>
// Set the state counter for toxic back to 0
this._toxicCounter = 0;
</Custom Remove Effect>

If that doesn't work, do:
<Custom Remove Effect>
// Set the state counter for toxic back to 0
this._toxicCounter = undefined;
</Custom Remove Effect>
I first tested your suggested alteration of the custom apply effect, which resulted in the following error:
Failed to execute 'createLinearGradient' on 'CanvasRenderingContext2D': The provided double value is non-finite
I think that error is because it's trying to add 1 to "undefined". Maybe try this instead:
Code:
<Custom Apply Effect>
if (this._toxicCounter === undefined) {
  this._toxicCounter = 0;
}
this._toxicCounter += 1;
</Custom Apply Effect>
Thank you so much, @caethyril ! That did the trick. You and @Fernyfer775 have been a great help. This topic is solved!

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/yanflys-toxic-effect-help.104141/