Actor Updating

question for ya'll, simple update issue i'm seeing that i'm sure someone understands. with my convenient effects module, i'm attempting to handle the spell Aid, which grants +5 healing and +5 max HP for the duration. i'm writing code to specifically do this, because active effects for this kind of stuff doesn't work. here's what i got
/**
* Adds actor data changes for specific effects
*
* @param {string} effectName - the effect name to handle
* @param {Actor5e} actor - the effected actor
*/
async addActorDataChanges(effectName, actor) {
switch (effectName.toLowerCase()) {
case 'aid':
await this._addAidEffects(actor);
break;
}
}

async _addAidEffects(actor) {
await actor.data.update({
'data.attributes.hp.max': actor.data.data.attributes.hp.max + 5,
'data.attributes.hp.value': actor.data.data.attributes.hp.value + 5,
});
}

/**
* Removes actor data changes for specific effects
*
* @param {string} effectName - the effect name to handle
* @param {Actor5e} actor - the effected actor
*/
async removeActorDataChanges(effectName, actor) {
switch (effectName.toLowerCase()) {
case 'aid':
await this._removeAidEffects(actor);
break;
}
}

async _removeAidEffects(actor) {
const newMax = actor.data.data.attributes.hp.max - 5;
const value = actor.data.data.attributes.hp.value;

await actor.data.update({
'data.attributes.hp.max': newMax,
});

if (value > newMax) {
await actor.data.update({
'data.attributes.hp.value': newMax,
});
}
}
/**
* Adds actor data changes for specific effects
*
* @param {string} effectName - the effect name to handle
* @param {Actor5e} actor - the effected actor
*/
async addActorDataChanges(effectName, actor) {
switch (effectName.toLowerCase()) {
case 'aid':
await this._addAidEffects(actor);
break;
}
}

async _addAidEffects(actor) {
await actor.data.update({
'data.attributes.hp.max': actor.data.data.attributes.hp.max + 5,
'data.attributes.hp.value': actor.data.data.attributes.hp.value + 5,
});
}

/**
* Removes actor data changes for specific effects
*
* @param {string} effectName - the effect name to handle
* @param {Actor5e} actor - the effected actor
*/
async removeActorDataChanges(effectName, actor) {
switch (effectName.toLowerCase()) {
case 'aid':
await this._removeAidEffects(actor);
break;
}
}

async _removeAidEffects(actor) {
const newMax = actor.data.data.attributes.hp.max - 5;
const value = actor.data.data.attributes.hp.value;

await actor.data.update({
'data.attributes.hp.max': newMax,
});

if (value > newMax) {
await actor.data.update({
'data.attributes.hp.value': newMax,
});
}
}
This all works well and dandy... unless foundry is reloaded. Then all the changes are lost and the max HP is set back to whatever it was before. I'm passing in the Actor5e from the selected token on the canvas. Anyone have any ideas?
37 Replies
Calego
Calego4y ago
Suspect you should be calling actor.update instead of actor.data.update
DFreds
DFredsOP4y ago
will that effect the 'prototype' version if applied to a derived token? also, is the syntax for that the same as what i'm doing just without the .data?
Calego
Calego4y ago
Ohhh I have no idea how to handle unlinked tokens
Unknown User
Unknown User4y ago
Message Not Public
Sign In & Join Server To View
Calego
Calego4y ago
I wanna say "no" to the first question
Unknown User
Unknown User4y ago
Message Not Public
Sign In & Join Server To View
DFreds
DFredsOP4y ago
hm let me try this and see. also, yay threads. long overdue feature
Unknown User
Unknown User4y ago
Message Not Public
Sign In & Join Server To View
DFreds
DFredsOP4y ago
oh, not on mobile, so haven't had that experience yet lol
async _addAidEffects(actor) {
await actor.update({
'data.data.attributes.hp.max': actor.data.data.attributes.hp.max + 5,
'data.data.attributes.hp.value': actor.data.data.attributes.hp.value + 5,
});
}
async _addAidEffects(actor) {
await actor.update({
'data.data.attributes.hp.max': actor.data.data.attributes.hp.max + 5,
'data.data.attributes.hp.value': actor.data.data.attributes.hp.value + 5,
});
}
alright that is not doing anything
Unknown User
Unknown User4y ago
Message Not Public
Sign In & Join Server To View
DFreds
DFredsOP4y ago
ah, it's not data.data. i guess it is still just data
Unknown User
Unknown User4y ago
Message Not Public
Sign In & Join Server To View
DFreds
DFredsOP4y ago
huh, looks like it does. the unlinked token is affected, but not the prototype version of it sweet, i think this is good now. i knew it had to be something simple and i just didn't know it
Unknown User
Unknown User4y ago
Message Not Public
Sign In & Join Server To View
DFreds
DFredsOP4y ago
so in summary
async _addAidEffects(actor) {
await actor.update({
'data.attributes.hp.max': actor.data.data.attributes.hp.max + 5,
'data.attributes.hp.value': actor.data.data.attributes.hp.value + 5,
});
}
async _addAidEffects(actor) {
await actor.update({
'data.attributes.hp.max': actor.data.data.attributes.hp.max + 5,
'data.attributes.hp.value': actor.data.data.attributes.hp.value + 5,
});
}
that works for all linked and unlinked tokens
Unknown User
Unknown User4y ago
Message Not Public
Sign In & Join Server To View
DFreds
DFredsOP4y ago
dang it wait oh lol. vim and copying. my b
Unknown User
Unknown User4y ago
Message Not Public
Sign In & Join Server To View
Calego
Calego4y ago
Yeah you're trying to update data.attributes with the value from actor.data.data.attributes
DFreds
DFredsOP4y ago
updated it
Unknown User
Unknown User4y ago
Message Not Public
Sign In & Join Server To View
DFreds
DFredsOP4y ago
👏 thanks all wait if i thank you in a thread, does it still give league points?
Unknown User
Unknown User4y ago
Message Not Public
Sign In & Join Server To View
DFreds
DFredsOP4y ago
also, can i thank you all at once 🤔
Unknown User
Unknown User4y ago
Message Not Public
Sign In & Join Server To View
DFreds
DFredsOP4y ago
lets try. thank you @theripper93 @calego @nekrodarkmoon
Leo The League Lion
@dfreds gave vote LeaguePoints™ to @theripper93 (#8 • 182), @calego (#1 • 1008), and @nekrodarkmoon (#27 • 65)
DFreds
DFredsOP4y ago
woohoo
Unknown User
Unknown User4y ago
Message Not Public
Sign In & Join Server To View
Calego
Calego4y ago
you get a lot of vote in your #progress-reports 😉
Unknown User
Unknown User4y ago
Message Not Public
Sign In & Join Server To View
DFreds
DFredsOP4y ago
speedrun to take over calego ready go
Unknown User
Unknown User4y ago
Message Not Public
Sign In & Join Server To View
DFreds
DFredsOP4y ago
lol
Unknown User
Unknown User4y ago
Message Not Public
Sign In & Join Server To View
Calego
Calego4y ago
😓 I'm like 90% sure we ditched the ability for that to be pinged
Unknown User
Unknown User4y ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server