YEP lunatic mode item that fills RAM

Hello, fellow RPG makers,
I've encountered a serious problem.
I wanted to create an item that based on which class equips it, gives different stats.
I achieved it with this code, using state 4 as a passive state.

<Custom Parameters>
if (user.isStateAffected (4) == true) {
atk = Math.floor($gameActors.actor(user.actorId()).param(3) * 25 / 100)
} else {
atk = 1000
}
</Custom Parameters>

There's nothing wrong with the syntax of the code I believe. However, the $gameActors.actor(user.actorId()).param(3) part is pretty hostile towards me. When I try to equip the item, it freezes the game and after a while the console tells me that maximum stacks have been reached, in other words the RAM is full.
As a result of that the game stops caring about the item effect anymore.
Interestingly enough, if I replace that part with a static number, everything works with no problems.

EDIT: I tried to simplify the code with user.param(3) * 25 / 100, but it achieves the exact same results 🙁



Ok, nevermind, I figured out the problem and the solution.
Solution first. I designated some variables to carry the values of heroes' attributes and made the item point to them. Now the problem...
Since the item overwrote the atk value by a portion of the attack value, it was an infinite recursion. So that means I have to do it through the variables to make the parameter a static number, not a recursion.
However, I will still have to do it differently to prevent the attack growing every moment...
If you are getting a freeze like that, that means you've created an infinite loop. Check your code and see what could be causing that.
First, user.isStateAffected(4) == true doesn't need the == true part to work; it just needs to be user.isStateAffected(4).

Second, I don't think $gameActors.actor is the best approach to doing what you're trying to accomplish. From what I can tell, you're trying to alter the atk of the user through their defense (param(3)). Try using something like this instead:

atk = user.paramBase(3) / 4;

I got this concept of Yanfly's Tips & Tricks video I'm linking here:



Hopefully, this will accomplish what you're going for.
Thank you all for the answers. Truth is, I formulated it very strangely, because I had a couple of mistakes in my own code (for example I wanted to raise attack based on attack, but wanted to raise it based on defence - although truth is, it still gave the error even when I based the attack on defence, so the problem would still be the same). I fixed them, but forgot to update them here.

However, I finally saw the reason why I got the infinite loop and now I am in the process of fixing it. Thank you very much though! 🙂

Original thread: https://forums.rpgmakerweb.com/threads/yep-lunatic-mode-item-that-fills-ram.78091/