Yanfly BuffStatesCore Stacks added to Poison

Hello, i'm using Yanfly BuffStatesCore and what i'm trying to do is make a state similar to poison where the longer the enemy is in the state, the more health they lose each turn. I've put this in the note tag to test it out


<Custom Apply Effect>
var stacks = 1;
stacks = stacks.clamp(1, 9);
</Custom Apply Effect>


<Custom Turn End Effect>
user.hp -= (10 * stacks);
stacks += 1;
stacks = stacks.clamp(1, 9);

</Custom Turn End Effect>
But nothing is happening.
But nothing is happening.
variables you declare do not exist outside of the notetag you define them in. the stacks variable you declared in the apply effect doesnt exist within the turn end effect. the way around usually it is to attach the variable to an existing object that can be referenced anywhere such as a battler or a GameVariable

user.hp -= (10 * stacks);
you cant modify a battler's HP like that. use the gainHp()function instead. battler.hp is actually a function call, not a value property.

var stacks = 1;
stacks = stacks.clamp(1, 9);
also if state application unconditionally sets that variable to a specific hardcoded value, there no need to clamp it. if you always set it to 1, it cant ever be above 9 or below 1.


Code:
<Custom Apply Effect>
user._poisonStacks = 1;
</Custom Apply Effect>


<Custom Turn End Effect>
user.gainHp(-10 * Math.min(user._poisonStacks, 9);
user.startDamagePopup() // you might not need this line. remove it if you get multiple popups
user._poisonStacks += 1;
</Custom Turn End Effect>
variables you declare do not exist outside of the notetag you define them in. the stacks variable you declared in the apply effect doesnt exist within the turn end effect. the way around usually it is to attach the variable to an existing object that can be referenced anywhere such as a battler or a GameVariable


you cant modify a battler's HP like that. use the gainHp()function instead. battler.hp is actually a function call, not a value property.


also if state application unconditionally sets that variable to a specific hardcoded value, there no need to clamp it. if you always set it to 1, it cant ever be above 9 or below 1.


Code:
<Custom Apply Effect>
user._poisonStacks = 1;
</Custom Apply Effect>


<Custom Turn End Effect>
user.gainHp(-10 * Math.min(user._poisonStacks, 9);
user.startDamagePopup() // you might not need this line. remove it if you get multiple popups
user._poisonStacks += 1;
</Custom Turn End Effect>
Ok thank you!

Original thread: https://forums.rpgmakerweb.com/threads/yanfly-buffstatescore-stacks-added-to-poison.175124/