[SOLVED]Need help with a state using Yanfly Buff & State core

I have created a state that adds a damage shield to the actor based on their luk stat. It works as is. The problem I'm having is coming up with a way to make the state stack. Currently, when the state is reapplied, it just resets the state counter to the original formula of Math.floor(user.luk * 2)

Technically this is okay, it is what I originally wanted. However, if possible I'd like to make it so that the state counter will add itself to whatever the current value is. So lets say the actors luk stat is 20, the state is applied and the actor will receive a damage shield of 40 = luk * 2. Lets say the actor takes 5 damage, so the state counter (the damage shield) is reduced to 35. If I reapply the state to the actor the next turn, the state counter returns to 40 (= luk * 2). Instead what I would like to happen is the state counter change to 75 (the original 35 plus another 40 based on the formula of Math.floor(user.luk * 2)).

Below is the states note tag box contents

Code:
<Custom Apply Effect>
// The number of damage before the shield wears off.
user._Protect = Math.floor(target.luk * 2);
// Set the state counter to display damage shield amount left.
user.setStateCounter(stateId, user._Protect);
</Custom Apply Effect>

<Custom Remove Effect>
// Remove the damage needed to expire the shield.
user._Protect = undefined;
// Reset the state counter.
user.setStateCounter(stateId, 0);
</Custom Remove Effect>

<Custom React Effect>
// Check if the action deals HP damage.
if (this.isHpEffect() && value > 0) {
  // Play an animation on the target.
  target.startAnimation(53);
  // Calculate the amount of HP to reduce.
  var reduce = Math.min(value, target._Protect);
  // Reduce that from the value.
  value -= reduce;
  // Reduce that value from the shield amount.
  target._Protect -= reduce;
  // Set the state counter to reflect the new damage shield amount left
  target.setStateCounter(stateId, target._Protect);
  // Create a text to display.
  var text = "<CENTER>" + target.name() + "'s protection aura blocks " + reduce + " damage."
  // Set the wait time.
  var wait = 90;
  // Display the text.
  BattleManager.addText(text, wait);
}
// Check if the damage shield is exhausted
if (target._Protect <= 0) {
  // Then remove the state.
  target.removeState(stateId);
}
</Custom React Effect>

I've been trying to figure this out for a day or so and I'm stumped. Hopefully someone can help me, thanks in advance.
Maybe try something like this for your Apply tag~
Code:
<Custom Apply Effect>
// Existing value, otherwise zero
user._Protect = user._Protect || 0;
// Add 2 * luk
user._Protect += user.luk * 2;
// Set state counter, for display
user.setStateCounter(stateId, user._Protect);
</Custom Apply Effect>
That worked exactly how I needed it, thank you!

I had tried doing something similar to this the other day. Either I had a typo or I did something else wrong, but when it didn't work I just moved on. My method had given my a counter of 'NaN' I don't remember exactly how I wrote it before, but regardless, thanks so much for the help @caethyril

edit: this is solved and can be closed

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/solved-need-help-with-a-state-using-yanfly-buff-state-core.123823/