mrkeathley / dark-heresy-2nd-vtt

Dark Heresy 2nd Edition - Foundry VTT System
GNU General Public License v3.0
3 stars 6 forks source link

Trying to use Assign Damage macro on token not linked to actor data throws Uncaught (in promise) error #26

Open jjhritz opened 10 months ago

jjhritz commented 10 months ago

Targeting a token linked to actor data works fine; wounds are deducted, critical damage is applied. It's only when targeting unlinked tokens that this error comes up.

Error occurs at https://github.com/mrkeathley/dark-heresy-2nd-vtt/blob/fb589eac717e68950c5d4148c3746c58a7d9f335/src/module/prompts/assign-damage-prompt.mjs#L26

Is it possible https://github.com/mrkeathley/dark-heresy-2nd-vtt/pull/18 missed referencing a uuid somewhere and is instead trying to reference actor data?

Foundry 11.308 Dark Heresy 2nd version: 1.7.1

Console output:

foundry.js:68147 actors is not a valid embedded Document within the Token Document
fetch @ foundry.js:68147
notify @ foundry.js:68044
error @ foundry.js:68081
_handleError @ foundry.js:3393
(anonymous) @ foundry.js:3375
value @ socket.js:532
value @ socket.js:459
L.emit @ index.mjs:136
(anonymous) @ manager.js:207
Promise.then (async)
it @ websocket-constructor.browser.js:5
value @ manager.js:206
L.emit @ index.mjs:136
value @ index.js:131
value @ manager.js:193
L.emit @ index.mjs:136
value @ socket.js:324
L.emit @ index.mjs:136
value @ transport.js:97
value @ transport.js:89
ws.onmessage @ websocket.js:69
assign-damage-prompt.mjs:26 Uncaught (in promise) Error: actors is not a valid embedded Document within the Token Document
    at Token.getEmbeddedCollection (file:///C:/Program%20Files/FoundryVTT/Foundry%20Virtual%20Tabletop/resources/app/common/abstract/document.mjs:610:13)
    at ServerDatabaseBackend._updateDocuments (file:///C:/Program%20Files/FoundryVTT/Foundry%20Virtual%20Tabletop/resources/app/dist/database/backend/server-backend.mjs:1:3414)
    at ServerDatabaseBackend.update (file:///C:/Program%20Files/FoundryVTT/Foundry%20Virtual%20Tabletop/resources/app/common/abstract/backend.mjs:133:17)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Semaphore._try (file:///C:/Program%20Files/FoundryVTT/Foundry%20Virtual%20Tabletop/resources/app/common/utils/semaphore.mjs:101:17)
_handleError @ foundry.js:3391
(anonymous) @ foundry.js:3375
value @ socket.js:532
value @ socket.js:459
L.emit @ index.mjs:136
(anonymous) @ manager.js:207
await in (anonymous) (async)
dispatch @ jquery.min.js:2
y.handle @ jquery.min.js:2
mrkeathley commented 10 months ago

Thanks for the issue. This is one that has been plaguing me for a while. It's hard to know what is actually desired when tokens can sometimes be an instance of a character (gangster) and sometimes refer to a named character (Inquisitor Graves). I have been wondering if there should be a flag on a character sheet to say if it's a 'type' -- so damage only goes to the token vs going to the character sheet. Alternatively, I should just make the code smarter to try and figure out the desired result based on if there is linked actor data or not.

jjhritz commented 10 months ago

The Link Actor Data toggle is supposed to control whether changes made to the token propagate back to the actor the token represents. I haven't yet found any API documentation to say specifically how to make sure that happens, but looking at code samples from other games, I think if you perform your operations on a "token" rather than an "actor", the LAD toggle will manage that behavior for you.

Either that, or you need to have the represented "actor" as a data member of the token. I'm not sure if that's default behavior (or, if it's not, why it wouldn't be).

My programming background is in C, not JS, so constructs like Promises and async are difficult for me to follow just reading looking at the code.

mrkeathley commented 10 months ago

Yeah, I believe you are correct. Although I am unsure if it actually propagates exactly as you expect. There have been some recent changes that I was unaware of as well: https://foundryvtt.com/article/v11-actor-delta/

There is now an token.actor and token.baseActor to distinguish between the clone and the source. I will make some updates to try and update the token first and confirm that it does indeed propagate to the actor if linked.