vtt-lair / simbuls-cover-calculator

A Foundry VTT module that calculates cover for DnD 5e
MIT License
6 stars 4 forks source link

How to use globalThis.CoverCalculator.Cover in scripts? #41

Closed Krigsmaskine closed 1 year ago

Krigsmaskine commented 1 year ago

This very well might just be me being inept, so thanks for your time regardless.

I'm trying to programmatically use Simbul's Four Corner Vision cover computation in a script and I'm doing something wrong, but I cannot figure out what. Can you give me an example of how to do this, or tell me what I'm doing wrong with my snippet?

UUIDs from two different tokens. I try to call the function, but then it errors with a Uncaught (in promise) TypeError: undefined. this.data.origin.object.ignoresCover is not a function

const caster = await fromUuid("Scene.YJRysjyBXChGr8Pu.Token.BDpfaksm1nYVt3Ec");
const target = await fromUuid("Scene.YJRysjyBXChGr8Pu.Token.wtf4fCJlsc9qnKGV")
const simbulCover = await globalThis.CoverCalculator.Cover(caster, target);

I saw that it might be checking for an array, but making the variables arrays instead seems to make the function think that caster = target with the custom error message of "Token Error", if I read the source correctly.