State auto-removal duration: Can I use a variable?

You know like you can set each state in RPGMV to a duration, for example 2-3 turns,

1fynfkR.png


but is there a script call where I could set this duration to a VARIABLE!?

I couldn't find anything in my research...
I would remove it on battle end (the check mark)

and create a common event that hold the variable or the states, and control there when the state is removed 🙂
other than that, I have no clue otherwise to be honest.
I'd suggest Yanfly's Buffs & States Core. It offers a <State x Turns: +y> tag for skills/items, nice and simple. It also offers the <Custom Apply Effect> notetag for states, so you can set the duration via script when the state gets applied, e.g.
Code:
<Custom Apply Effect>
var turns = $gameVariables.value(1);
user.setStateTurns(stateId, turns);
</Custom Apply Effect>
This, verbatim, will set the state's duration to the value of game variable 1; just replace the 1 with the variable ID you want to reference. 🙏

Also, in case it helps: you can get the current turn count with this~
Code:
user.stateTurns(stateId)


Edit: just noticed this is in Learning JavaScript, so I'll add some more explanation. Note that both stateTurns and setStateTurns are methods added by Yanfly's Buffs & States Core. The real use of the plugin here is to give an appropriate trigger for the script call. State turn counts are stored in an array on the battler, so you can, for example, set state 5's duration to 3 turns like this:
Code:
user._stateTurns[5] = 3;

Original thread: https://forums.rpgmakerweb.com/threads/state-auto-removal-duration-can-i-use-a-variable.113174/