I tried asking this in the notetag help thread but didn't have any luck:
So I set up an equipment piece with a Passive state with a passive condition:
<JS Passive Condition>
if (user.hp / user.mhp >= 0.9) {
condition = true; }
else { condition = false; }
</JS Passive Condition>
So this code works, the problem is that hovering over the equipment that has this passive state in the Item or Equip menus causes a massive lagspike (the game freezes for 2-4 seconds).
Did I do something wrong with how I structured the code or is this lagspike just supposed to happen due to the calculations?
The code within the tag seems alright. The lag spike must be because of something else.
Yeah, that's what I was afraid of. meh
I guess I'll try reporting it to the team as a bug...
Well are you sure that it is THAT specific plugin from VisuStella that causes the lagspike?
Because if you are the only one experiencing this problem, then the problem may come from elsewhere.
It is possible that the calculation of the hpRate() could go through a complicated computation, but I don't believe that was the case. Try to make the condition simpler, such as checking the variable value if it is bigger/smaller. See if it still lags.
I've tried a few different variations with the same result, but I've noticed something interesting: making any equation that involves "user.mhp" causes the flurry of RangeErrors above. Working with just "user.hp" works normally.
Unfortunately, I'm wanting the passive state to check what the user's current hp is to their current max hp - and anything involving max HP causes the overflow error. Even just setting a variable to the user's max HP causes the stack overflow.
I guess I'll try to submit a bug report to VisuStella...
Well, guess I have one more in my "to do" list xD
Hey now that the more I think about it, the more that the lag actually makes sense.
Here is why...
First of all, max hp is calculated based on various traits. Including actor, class, weapon, armor, and yes, states. This is probably not what your passive state does, but what if you make a state that increases max hp by 120%while adding user.hpRate() > 0.9 as the condition. Yes, that would create a paradox and infinite loop!
But even if the state is not actually increasing the max hp, it still causes a loop (I only mention that to demonstrate that states affect max hp). First of all, when you query the user's max hp, it queries the available states. By default, it would be alright, but when you add passive states with JS syntax condition that querying user max hp, there you have the problem.
To put this simply
Query: maxHP --> calculate the max hp --> querying states (passive included) --> Passive states requires the amount of max HP resolved first --> calculating the max hp --> infinite loop.
I hope that makes sense.
It is not impossible. The passive state application must be designed in a certain way to avoid this problem (I might make my own version of passive state). Unfortunately, I can not help you with Visustella's problem for obvious reasons.