[FIXED]TypeError: Cannot read property '2' of undefined

Hello there,
I'm using this code on a state notag for stacking buff. It work fine but at the end of the state/battle, the stats buffed keep. The State is set up for be removed at the end of the fight.


Spoiler: Code
Code:
<Custom Apply Effect>
user._stack = user._stack || 0;
user._paramUp = user._paramUp || [];
for(i = 2; i < 6; i++){
user._paramUp[i] = user._paramUp[i]  || (Math.round(user.param(i) * 0.25));
if(user._stack < 2){
user.addParam(i, user._paramUp[i]);
}
}
user._stack++;
user._stack = Math.min(user._stack, 2);
</Custom Apply Effect>
<Custom Remove Effect>
user._stack = user._stack || 0;
user._paramUp = user._paramUp || [];
for(j = user._stack; j > 0; j--){
for(i = 2; i < 6; i++){
user._paramUp[i] = user._paramUp[i]  || (Math.round(user.param(i) * 0.25));
if(j > 0){
user.addParam(i, -user._paramsUp[i]);
}
}
}
user._stack = undefined;
user._paramUp = undefined;
</Custom Remove Effect>
----------------------------
Spoiler: Error Console
Code:
TypeError: Cannot read property '2' of undefined
    at eval (eval at Game_Battler.customEffectEval (YEP_BuffsStatesCore.js:1378), <anonymous>:7:33)
    at Game_Actor.Game_Battler.customEffectEval (YEP_BuffsStatesCore.js:1378)
    at Game_Actor.Game_Battler.removeStateEffects (YEP_BuffsStatesCore.js:1411)
    at Game_Actor.Game_Battler.removeState (YEP_BuffsStatesCore.js:1405)
    at Game_Actor.Game_Battler.removeState (YEP_X_VisualStateFX.js:308)
    at Game_Actor.Game_Battler.removeState (YEP_AutoPassiveStates.js:566)
    at Game_Actor.Game_BattlerBase.updateStateTurnTiming (YEP_BattleEngineCore.js:3633)
    at Game_Actor.Game_BattlerBase.updateStateTurnTiming (YEP_BuffsStatesCore.js:1513)
    at Game_Actor.Game_BattlerBase.updateStateTurnEnd (YEP_BattleEngineCore.js:3650)
    at Game_Actor.Game_BattlerBase.updateStateTurns (YEP_BattleEngineCore.js:3610)
----------------------------
Spoiler: Impacted Code
Code:
 user._stack = user._stack || 0;
user._paramUp = user._paramUp || [];
for(j = user._stack; j > 0; j--){
for(i = 2; i < 6; i++){
user._paramUp[i] = user._paramUp[i]  || (Math.round(user.param(i) * 0.25));
if(j > 0){
user.addParam(i, -user._paramsUp[i]);
}
}
}
user._stack = undefined;
user._paramUp = undefined;
Hello there,
I'm using this code on a state notag for stacking buff. It work fine but at the end of the state/battle, the stats buffed keep. The State is set up for be removed at the end of the fight.


Spoiler: Code
Code:
<Custom Apply Effect>
user._stack = user._stack || 0;
user._paramUp = user._paramUp || [];
for(i = 2; i < 6; i++){
user._paramUp[i] = user._paramUp[i]  || (Math.round(user.param(i) * 0.25));
if(user._stack < 2){
user.addParam(i, user._paramUp[i]);
}
}
user._stack++;
user._stack = Math.min(user._stack, 2);
</Custom Apply Effect>
<Custom Remove Effect>
user._stack = user._stack || 0;
user._paramUp = user._paramUp || [];
for(j = user._stack; j > 0; j--){
for(i = 2; i < 6; i++){
user._paramUp[i] = user._paramUp[i]  || (Math.round(user.param(i) * 0.25));
if(j > 0){
user.addParam(i, -user._paramsUp[i]);
}
}
}
user._stack = undefined;
user._paramUp = undefined;
</Custom Remove Effect>
----------------------------
Spoiler: Error Console
Code:
TypeError: Cannot read property '2' of undefined
    at eval (eval at Game_Battler.customEffectEval (YEP_BuffsStatesCore.js:1378), <anonymous>:7:33)
    at Game_Actor.Game_Battler.customEffectEval (YEP_BuffsStatesCore.js:1378)
    at Game_Actor.Game_Battler.removeStateEffects (YEP_BuffsStatesCore.js:1411)
    at Game_Actor.Game_Battler.removeState (YEP_BuffsStatesCore.js:1405)
    at Game_Actor.Game_Battler.removeState (YEP_X_VisualStateFX.js:308)
    at Game_Actor.Game_Battler.removeState (YEP_AutoPassiveStates.js:566)
    at Game_Actor.Game_BattlerBase.updateStateTurnTiming (YEP_BattleEngineCore.js:3633)
    at Game_Actor.Game_BattlerBase.updateStateTurnTiming (YEP_BuffsStatesCore.js:1513)
    at Game_Actor.Game_BattlerBase.updateStateTurnEnd (YEP_BattleEngineCore.js:3650)
    at Game_Actor.Game_BattlerBase.updateStateTurns (YEP_BattleEngineCore.js:3610)
----------------------------
Spoiler: Impacted Code
Code:
 user._stack = user._stack || 0;
user._paramUp = user._paramUp || [];
for(j = user._stack; j > 0; j--){
for(i = 2; i < 6; i++){
user._paramUp[i] = user._paramUp[i]  || (Math.round(user.param(i) * 0.25));
if(j > 0){
user.addParam(i, -user._paramsUp[i]);
}
}
}
user._stack = undefined;
user._paramUp = undefined;
Code:
if(j > 0){
  user.addParam(i, -user._paramsUp[i]);
}
_paramsUp isn't defined... 😛
omfg how can i missed that... I passed 2 hour to try to understand why that don't work... And just for an error like that... Kill me plz... 😅

Thanks you by the way ! 😅😅😅
It happens, don't worry. Happy RPG Making! 🙏

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/fixed-typeerror-cannot-read-property-2-of-undefined.111335/