jessev14 / health-monitor

Foundry VTT module that implements simple tracking of changes to HP.
MIT License
5 stars 2 forks source link

[BUG] When closing Player/NPC sheets Health Monitor reports "[NAME] takes 0 damage" [Foundry V12] #16

Open kiloforce opened 4 months ago

kiloforce commented 4 months ago

When either DM or player closes any character sheet, the Health Monitor reports to chat "[NAME] takes 0 damage".

image

Foundry v12.330 Health Monitor Module v3.1.0

kiloforce commented 4 months ago

The Javascript console is pretty quiet and unhelpful in trying determine the cause here:

image

Fridan99 commented 3 months ago

same problem Dnd5e system 3.3.1 Foundry v12.330 Health Monitor Module v3.1.0

kiloforce commented 3 months ago

Looks like the code should already handle this "zero" situation:

                // If delta is null or 0, return
                if (!v) continue;

Which means whatever is coming across is not actually a zero. Likely whatever the actual value that is coming across is something that is just resolving down to zero in the math abs() function:

[Math.abs(v)](delta: Math.abs(v),)

In which case, could do something like:

                // If delta is null or 0, return
                if (!v || Math.abs(v) == 0) continue;
kiloforce commented 3 months ago

Nope, did some testing. This is not where the problem is. Turns out there is a second section that also captures deltas, that wasn't checking for zeros. Still not sure why this wasn't a problem until v12. Just simply added this same zero check there, and seemed to solve the problem.

main.js:

    // For each HP delta, create a chat message.
    for (const [k, delta] of Object.entries(deltas)) {
        // If delta is null or 0, return
        if (!delta) continue;
kiloforce commented 3 months ago

I don't know when the original author will pull in these pull requests, so in the meantime, if you want to try out the fixes, you can load a preview build here:

Install Module - Manifest URL - https://github.com/kiloforce/health-monitor/releases/latest/download/module.json