MZ Change NaN to Zero

Hello,

I have a "hopeless boss fight" at the very start of my project where the player is not meant to be able to do any damage to the enemy. I have all the stats working to make that happen, but the issue is it makes every attack return "NaN" which I just think looks ugly and distracting. I would rather it return 0.

I was wondering if anyone could point me to a plug-in (or option in the VS core that I'm overlooking) to globally change NaN to zero.
The correct thing to do would be to fix whatever formula is producing NaN - which means "not a number."

That means there's a flaw in your damage formula which is producing an invalid result, which is not going to only affect that boss fight.
The correct thing to do would be to fix whatever formula is producing NaN - which means "not a number."

That means there's a flaw in your damage formula which is producing an invalid result, which is not going to only affect that boss fight.
The formula in question is the basic attack, which works fine against other foes. If I had to guess it's returning NaN because the result of that formula is a negative number due to the boss's Def being so high. Which I could lower; but I really need the damage to always be 0 for story reasons so variance becomes an issue; which I don't want off for the entire game.

Is there something I can put in the attack formula to take an absolute value? ignore that; that would be really wrong.
A negative result would not cause this problem.

This page lists cases that can produce NaN:
I imagine your situation is likely to be one of the following:
  1. A fractional power of a negative number, e.g. (a.atk - b.def) ** 0.5;
  2. The indeterminate form 0 * Infinity (e.g. 0 / 0).
What formula are you using for this basic attack skill?
A negative result would not cause this problem.

This page lists cases that can produce NaN:
I imagine your situation is likely to be one of the following:
  1. A fractional power of a negative number, e.g. (a.atk - b.def) ** 0.5;
  2. The indeterminate form 0 * Infinity (e.g. 0 / 0).
What formula are you using for this basic attack skill?

Code:
a.atk * 2 - b.def

1714764959067.png


Addendum: I also just noticed it's displaying NaN on the enemy at the end of each round as well, which makes no sense since the "attack" they use doesn't have a type or do any damage. Strangely, this one vanishes if I raise the Actor's level.
That cannot produce this error, the error has to be caused by something else.

Please post a full screenshot of the skill and of the enemy itself so that we can check the values.
also post screenshots of your plugin manager so that we can see which plugins might interfere with the battle or the skills.

And a question about your testing: Are youusing the database battletest, continue a saved gamefile or started a new game?
If you haven't done so, please test if this error happens on a new game from the titlescreen.
The skill: 1714765590466.png

The enemy:
1714765669285.png


Plugin list:
1714765700638.png


It happens both in battle test and on a new game. I can't continue from a saved one because this happens before the player is able to open the menu.
Are you using plugins that may interfere with/alter the damage calculation?
Unless you gave the target a 0% Guard Effect Rate and have it defend (Edit3: That case does not cause NaN) I would not know how you would achieve NaN otherwise (or broken traits).

You could try to open the developer console (F8) during combat and use this code to print out some of the steps of the normal damage calculation process (also whether the damage calculation function was modified):
Replace the 0 in line 2 and 3 if you are not using the first party/troop member as reference.
Code:
{
    let subject = $gameParty.members()[0];
    let target = $gameTroop.members()[0];

    let action = new Game_Action(subject);
    let result = "";
    action.setAttack();
    let baseValue = action.evalDamageFormula(target);
    result += "Formula: " + baseValue;
    result += "\nElement: " + action.calcElementRate(target);
    result += "\nPhysical: " + (action.isPhysical() ? target.pdr : "N/A");
    result += "\nMagical: " + (action.isMagical() ? target.mdr : "N/A");
    result += "\nCritical: " + action.applyCritical(baseValue);
    result += "\nVariance: " + action.applyVariance(baseValue, action.item().damage.variance);
    result += "\nGuard: " + action.applyGuard(baseValue, target);
    result += "\n\nTotal Damage: " + action.makeDamageValue(target);
    result += "\n\nDamage Function:\n" + action.makeDamageValue;
    result += "\n\nFormula Function:\n" + action.evalDamageFormula;
    console.log(result);
}

Edit: A bit slow, also typo
Edit2: another typo
Are you using plugins that may interfere with/alter the damage calculation?
Unless you gave the target a 0% Guard Effect Rate and have it defend I would not know how you would achieve NaN otherwise (or broken traits).
Not that I know of? I posted my plug-in list and none of them change the base damage calc as far as I know.

You could try to open the developer console (F8) during combat and use this code to print out some of the steps of the normal damage calculation process (also whether the damage calculation function was modified):
It came back with this:
1714766572498.png

And to be honest I have no idea what any of that means.
The simple first troubleshooting test is to turn off all of your plugins, save your project, start a new play test.

Addendum: I also just noticed it's displaying NaN on the enemy at the end of each round as well
This sounds like it has nothing to do with the attack at all.

It sounds like something that's trying to happen during the regeneration phase or some other thing that's been added in via plugins.

What is that "battlespeed" plugin?
The simple first troubleshooting test is to turn off all of your plugins, save your project, start a new play test.
Edit: Okay turning off everything fixed it....
This sounds like it has nothing to do with the attack at all.

It sounds like something that's trying to happen during the regeneration phase or some other thing that's been added in via plugins.
I have no idea what may be doing that; since I haven't given this enemy regen and it doesn't happen with other enemies.

What is that "battlespeed" plugin?

Something I made based on a tutorial to change how fast battle messages are displayed. Because I thought it was too fast.


Code:
       Window_BattleLog.prototype.messageSpeed = function() {
    return 38;
};

Disabling it didn't fix the NaN's.
Disabling it didn't fix the NaN's.
Okay...but that's just one piece of what I said. Can you confirm they go away when you disable all your plugins?

You said it stops when you make the actors a higher level, so where's a screenshot of their parameters at level 1 or whatever they are?
Okay...but that's just one piece of what I said. Can you confirm they go away when you disable all your plugins?

You said it stops when you make the actors a higher level, so where's a screenshot of their parameters at level 1 or whatever they are?
I missed that first part at first; I edited my previous post; yes it goes away if I turn off *everything*.

Here's the stats for that fight:
1714768346304.png


I'm going to test turning the plug-ins back on one by one and see when I get NaNs.

Result: In a dramatic case of irony; the plugin that produces the NaNs (even when nothing else is on). Is your TUR_EvalTags plugin.

Result 2: Turning everything except that one on returns 0 not NaN. So clearly, I did something very, very wrong implementing your plug in.
Doesnt the visustella skills and states plugin do most if not everything that EvalTags does? What do you use it for that isnt covered by visustella? I always saw it as a lightweight alternative if you just wanted eval tags without the 80 other things visustella adds.
Doesnt the visustella skills and states plugin do most if not everything that EvalTags does? What do you use it for that isnt covered by visustella? I always saw it as a lightweight alternative if you just wanted eval tags without the 80 other things visustella adds.

I think I can get away without the EvalTags; I got it first before I installed the VS plug-ins for an effect that I ended up scrapping because I asked the wrong question. So I think this is resolved? But it's weird result.
You've probably made a mistake somewhere in those eval tags, which would likely still happen if you used another plugin for them.

I'd recommend sharing the contents of those evals, especially related to this enemy. We might be able to help you find where that mistake is.
Doesnt the visustella skills and states plugin do most if not everything that EvalTags does?
Actually, more notetags come from the VisuStella Battle Core than the Skills & States. But yes, the point remains that it was not designed to be compatible with any VisuStella plugins.

If you can duplicate any kind of bug using just the Eval Tags, let me know and I'll fix it, but there's no point in trying to troubleshoot it with VisuStella in the project.
You've probably made a mistake somewhere in those eval tags, which would likely still happen if you used another plugin for them.

I'd recommend sharing the contents of those evals, especially related to this enemy. We might be able to help you find where that mistake is.
Note tag was empty for that enemy.

If you can duplicate any kind of bug using just the Eval Tags, let me know and I'll fix it, but there's no point in trying to troubleshoot it with VisuStella in the project.
When I run the playtest with only your script on, I get the NaN's; would I need to fully uninstall everything to fully test it or does turning it all off work?
It might also just be one of your note tags misfiring, I don't recall if the plugin had the option to change the damage value after the fact, or if that was only a VisuStella feature.

You could try this to check the active tags maybe (in the developer console):
Code:
{
    let subject = $gameParty.members()[0];
    let target = $gameTroop.members()[0];
    
    let extractNotetags = (obj => obj.note.match(/<([^>]+)>.*?<\/\1>/gis) || []);
    
    "user notetags:\n\n"
        + subject.traitObjects().flatMap(extractNotetags).join("\n")
        + "\n\ntarget notetags:\n\n"
        + target.traitObjects().flatMap(extractNotetags).join("\n")
        + "\n\nItem notetags:\n\n"
        + extractNotetags($dataSkills[subject.attackSkillId()]).join("\n");
}
It might also just be one of your note tags misfiring, I don't recall if the plugin had the option to change the damage value after the fact, or if that was only a VisuStella feature.

You could try this to check the active tags maybe (in the developer console):
Code:
{
    let subject = $gameParty.members()[0];
    let target = $gameTroop.members()[0];
   
    let extractNotetags = (obj => obj.note.match(/<([^>]+)>.*?<\/\1>/gis) || []);
   
    "user notetags:\n\n"
        + subject.traitObjects().flatMap(extractNotetags).join("\n")
        + "\n\ntarget notetags:\n\n"
        + target.traitObjects().flatMap(extractNotetags).join("\n")
        + "\n\nItem notetags:\n\n"
        + extractNotetags($dataSkills[subject.attackSkillId()]).join("\n");
}
It returned as:


Code:
"user notetags:



target notetags:



Item notetags:

"

There really is nothing being evaled here; but somehow this plug in is still doing weird things; even by itself.

Original thread: https://forums.rpgmakerweb.com/threads/change-nan-to-zero.168303/