MonsterBlocks icon indicating copy to clipboard operation
MonsterBlocks copied to clipboard

Character sheet won't open if a bad damage formula is used

Open RikkiGibson opened this issue 2 years ago • 2 comments

I used the damage formula [email protected] for a monster's attack, then hit save, and found I wasn't able to open the monster's character sheet back up. I had to disable the mod, correct the bad formula, then re-enable the mod.

TypeError: right-hand side of 'in' should be an object, got number
[Detected 2 packages: monsterblock, system:dnd5e]
    getProperty common/utils/helpers.mjs:295
    replaceFormulaData scripts/foundry.js:7072
    replaceFormulaData scripts/foundry.js:7071
    parse scripts/foundry.js:7032
    Roll scripts/foundry.js:6591
    damageFormula modules/monsterblock/scripts/dnd5e/AttackPreper.js:251
    formatAttackAndDamage modules/monsterblock/scripts/dnd5e/AttackPreper.js:189
    getDamageData modules/monsterblock/scripts/dnd5e/AttackPreper.js:166
    getAllDamageData modules/monsterblock/scripts/dnd5e/AttackPreper.js:148
    getDescription modules/monsterblock/scripts/dnd5e/AttackPreper.js:53
    prepare modules/monsterblock/scripts/dnd5e/AttackPreper.js:21
    prepareItem modules/monsterblock/scripts/dnd5e/ItemPrep.js:123
    organizeFeatures modules/monsterblock/scripts/dnd5e/ItemPrep.js:105
    prepareItems modules/monsterblock/scripts/dnd5e/ItemPrep.js:62
    ItemPrep modules/monsterblock/scripts/dnd5e/ItemPrep.js:36
    _prepareItems modules/monsterblock/scripts/dnd5e/MonsterBlock5e.js:494
    getData systems/dnd5e/module/actor/sheets/base.js:158
    getData systems/dnd5e/module/actor/sheets/npc.js:78
    getData modules/monsterblock/scripts/dnd5e/MonsterBlock5e.js:64
    _render scripts/foundry.js:3062
    _render scripts/foundry.js:3764
    render scripts/foundry.js:3021
    render scripts/foundry.js:4259
    _onClickDocumentName scripts/foundry.js:47577
    jQuery 2
foundry.js:319:30

RikkiGibson avatar Sep 05 '22 21:09 RikkiGibson

Error is still occurring. Foundry v10 build 291 DnD5e system v2.1.5 Monster Blocks v3.3.5 image

guldelox avatar May 11 '23 19:05 guldelox

@zeel01 I looked into this one and it appears to be fixed in the latest stable version of foundry. The getProperty method (see below) seems to explicitly return undefined if the input key doesn't give an Object or Array type, which should prevent the error from occurring. Might want to confirm against an older version just to be certain, but I think this one can be closed.

    if ( !key ) return undefined;
    let target = object;
    for ( let p of key.split('.') ) {
      const t = getType(target);
      if ( !((t === "Object") || (t === "Array")) ) return undefined;
      if ( p in target ) target = target[p];
      else return undefined;
    }
    return target;
  }

LunarShade avatar Feb 29 '24 01:02 LunarShade