Trouble with Synthetic Actors (unlinked tokens)

When I create a token from an actor and try to update something like its hp, I get the following error: "actors is not a valid embedded Document within the Token Document". If I link the token to the actor, everything works as expected. Though, being linked, it updates all tokens. This would be problematic If I want to create one "goblin" actor, and have several different goblins in a scene.
Is there something different you need to do to handle updates when the token is unlinked?
F
Forien•100d ago
it's tokenDocument.actor, not tokenDocument.actors. And you update it just as usual, tokenDocument.actor.update(updateData), you do not need to know or care if it's linked or unlinked, Foundry does that part.
E
Eclipxs•100d ago
I don't have any tokenDocument.actor or .actors calls. The only thing I see that would be executing in this path is: this.actor.receiveDamage(...) from a sheet, which then calls: this.update({ "system.lifePoints.value": remainingLifePoints }); from the actor class oh and there is a second path that comes from a button in a chat message. It grabs the current users target and then calls the receiveDamage on the targeted actor. I tried changing that path to go through tokenDocument.actor, but got the same error.
F
Forien•100d ago
Seeing actual error that points to specific file and related code would definitely help
E
Eclipxs•100d ago
one sec
E
Eclipxs•100d ago
chat handler:
function getTarget(actor = {}) {
const targets = game.users.current.targets;
let target = actor;
for (const t of targets) {
target = t.actor;
}
return target;
}

function onRenderChatMessage(app, html, data) {
html.find(".apply-outcome")
.click(async e => {
//todo apply outcomes: Bonus damage from good rolls?
const currentCharacter = game.users?.current?.character;
const target = getTarget(currentCharacter);
const message = data.message;
if (target && message?.flags?.rsk?.actionType) {
const dialog = RSKApplyDamageDialog.create(foundry.utils.deepClone(message.flags.rsk));
const result = await dialog();
if (!(result && result.confirmed)) return;
target.receiveDamage({ ...result });
}
});
}
function getTarget(actor = {}) {
const targets = game.users.current.targets;
let target = actor;
for (const t of targets) {
target = t.actor;
}
return target;
}

function onRenderChatMessage(app, html, data) {
html.find(".apply-outcome")
.click(async e => {
//todo apply outcomes: Bonus damage from good rolls?
const currentCharacter = game.users?.current?.character;
const target = getTarget(currentCharacter);
const message = data.message;
if (target && message?.flags?.rsk?.actionType) {
const dialog = RSKApplyDamageDialog.create(foundry.utils.deepClone(message.flags.rsk));
const result = await dialog();
if (!(result && result.confirmed)) return;
target.receiveDamage({ ...result });
}
});
}
actor method:
async receiveDamage(damage) {
const { puncture, damageEntries, attackType, defenseRoll } = { ...damage };
const damageTaken = this.calculateDamageTaken(damageEntries, attackType, puncture, defenseRoll);
const remainingLifePoints = game.rsk.math.clamp_value(
this.system.lifePoints.value - damageTaken,
{ min: 0 });
if (remainingLifePoints < 1 && !this.statuses.has("dead")) {
const death = rskStatusEffects.find(x => x.id === "dead");
await this.createEmbeddedDocuments("ActiveEffect", [statusToEffect(death)]);
}
this.update({ "system.lifePoints.value": remainingLifePoints });
}
async receiveDamage(damage) {
const { puncture, damageEntries, attackType, defenseRoll } = { ...damage };
const damageTaken = this.calculateDamageTaken(damageEntries, attackType, puncture, defenseRoll);
const remainingLifePoints = game.rsk.math.clamp_value(
this.system.lifePoints.value - damageTaken,
{ min: 0 });
if (remainingLifePoints < 1 && !this.statuses.has("dead")) {
const death = rskStatusEffects.find(x => x.id === "dead");
await this.createEmbeddedDocuments("ActiveEffect", [statusToEffect(death)]);
}
this.update({ "system.lifePoints.value": remainingLifePoints });
}
the actual errors are in the screenshots. They are almost the same, but slightly different. the one in common.js:8099 was from clicking my chat button. and the one in foundry.js:6629 is from editing the sheet from the unlinked actor directly.
No description
E
Eclipxs•100d ago
accidentally attached same image twice, here is the other one
No description
F
Forien•99d ago
It's hard to tell... errors definitely say that something tries to update embedded document called "actors"... maybe some _onUpdate() or _preUpdate() or some hook? I never encountered this before...
E
Eclipxs•99d ago
I was able to get rid of the error by removing my update call. But I do need to deal damage to my npc :/. I'll go look at my on update and pre updates and see if something weird is in there nope I don't use preUpdate or onUpdate anywhere what do you do when you want to be able to update an unlinked actor? or has it just worked for you is what you are saying?
F
Forien•99d ago
unlinked actor is still an Actor Document, so I just go actor.update() or token.actor?.update(). There really is no difference on higher level between linked and unlinked tokens and in most cases you should not need to care about distinction 🤔
E
Eclipxs•99d ago
well that is what I was hoping to hear... but somehow it makes me more sad haha
F
Forien•99d ago
what Foundry version are you using?
E
Eclipxs•99d ago
v11 build 315
F
Forien•99d ago
and socket.js is your system file?
E
Eclipxs•99d ago
socket.js would be part of foundry no? it isn't mine
F
Forien•99d ago
hm, could be, but can't find it ;P
E
Eclipxs•99d ago
my files in the stack are "RSK*"
F
Forien•99d ago
anyway, I think you should try asking on Foundry discord in the #dev-support channel
E
Eclipxs•99d ago
ok thanks don't do this: CONFIG.Actor.documentClass = SomeActorProxy;
Want results from more Discord servers?
Add your server
More Posts
Avoid Sheet Re-render When Editing Actor's Item**TL;DR** How do I avoid a re-render of a character sheet with actor.items displayed, that happens wHow to Create & Save Custom Field Values from a Dropdown on Actor sheet?I am building a custom system for a Hogwarts setting using the Wands & Wizards 5e supplement. I am cFinding target when making an attackI’m developing a game system, and can’t figure it out, when there is combat active and a player is tTrying to register a new systemHey everyone, I am new to Foundry system development. I am working with the boilerplate system and hMinimise Document using PrototypeQuick question, I've got no idea what I'm doing so please excuse my ineptitude. Say I have a documenNew to System Development but have done minor module developmentI am trying to see if there is a complete working model of a system that I could use a base to undercalculating range/distanceI am trying to calculate the distance between two tokens to make sure they are in range of one anothPartial RerollI am looking for a way to partially "reroll" a roll. Quick example: Player rolls 2d6 (a 2 and a 5) atiered status effectsIf I have a status effect that can come from an ability, for example, burning comes from an ability Importing an npm package into a foundry systemimport minimist from 'minimist'; That line alone when included in my module's hook file is resultin(Paid) System Dev AssistanceHello, I am developing a new game and would like to build my own game system in foundry vtt. I'm nothow to handle items and effects?I've been working on a system for a game that needs a concept that seems like it might be a good fitAdvice on the general programming model a system should followI'm brand new to foundry dev and I want to make sure I am gaining the correct understanding of the eAdvice for compendium data in a custom systemHello, i'm new here! I was wondering if I could get a little direction for storing data about my gaDialog Box Auto-Closing Upon Opening 2nd TimeI've been appending custom functionality to the simple worldbuilding system. At this time, I'm tryinActor collisionImplementing the homebrew knockback feature. It's almost working but how do I test if two actor tokeActor attributes update on player's sideI can't fathom how to make changes to actor attributes on player's side. According to documentation Sort itemsHello, I am searching for where is stored the data about "items" order, as I would like to order thNewby accepting advice on the Foundry API and Module DevelopmentHeya,im very new to Module development for foundry and im suuuuper rusty in the codding department bHow do I create/modify embedded document types?Let's say I want Items to also have Items embedded