Absolutely new to all of this, need help with a silly query.

Hello! I'm extremely new to all of this, and i'm having issues trying to understand how to code a way for the system to calculate the health of my character sheets. I've created in template.json an Actor and modified the "base" template to include the attribute "Health" which is composed of: "health": { "value": 10, "min": 0, "max": "@attributes.maxHealth" }, and that leads down to "character": { "templates": ["base"], "attributes": { "level": { "value": 1 }, "maxHealth":{ "formula":"72 + (@abilities.for.value * 8)", "min": 0 } }, The thing is, i have an ability called "for", short for Fortitude. And when i create an Actor in my test environment, it spits out the literal "72 + (abilities.for.value * 8" as a Text. How would i go on to actually make it do the math? Thank you beforehand for taking the time to read this!
6 Replies
Forien
Forien•9mo ago
I might be wrong, but I think template is now deprecated in favor of Data Models, which is preferred. Not saying using templates is wrong, but its old way of doing it. Anyway, I do not see your entire template here, so not 100% sure on cause, but assuming fortitude is defined leave one question: have you added fortutide to Roll Data? 🤔
Ashby Blackburn
Ashby BlackburnOP•9mo ago
Ah, Hello! Disregarding the part of my table that includes Items, my Template file looks like this:
"Actor": {
"types": ["character", "npc"],
"templates": {
"base": {
"health": {
"value": 10,
"min": 0,
"max": "72+(@abilities.for.value * 8)"
},
"light": {
"value": 5,
"min": 0,
"max": 5
},
"stagger": {
"value": 5,
"min": 0,
"max": 5
},
"sanity": {
"value": 5,
"min": 0,
"max": 5
},
"biography": ""
}
},
"character": {
"templates": ["base"],
"attributes": {
"level": {
"value": 1
}
},
"abilities": {
"for": {
"value": 0,
"imagePath": "systems/pmtrpg/assets/FortitudeIcon.webp"
},
"pru": {
"value": 0,
"imagePath": "systems/pmtrpg/assets/PrudenceIcon.webp"
},
"jus": {
"value": 0,
"imagePath": "systems/pmtrpg/assets/JusticeIcon.webp"
},
"cha": {
"value": 0,
"imagePath": "systems/pmtrpg/assets/CharmIcon.webp"
},
"ins": {
"value": 0,
"imagePath": "systems/pmtrpg/assets/InsightIcon.webp"
},
"tem": {
"value": 0,
"imagePath": "systems/pmtrpg/assets/TemperanceIcon.webp"
}
}
},
"npc": {
"templates": ["base"]
}
},
"Actor": {
"types": ["character", "npc"],
"templates": {
"base": {
"health": {
"value": 10,
"min": 0,
"max": "72+(@abilities.for.value * 8)"
},
"light": {
"value": 5,
"min": 0,
"max": 5
},
"stagger": {
"value": 5,
"min": 0,
"max": 5
},
"sanity": {
"value": 5,
"min": 0,
"max": 5
},
"biography": ""
}
},
"character": {
"templates": ["base"],
"attributes": {
"level": {
"value": 1
}
},
"abilities": {
"for": {
"value": 0,
"imagePath": "systems/pmtrpg/assets/FortitudeIcon.webp"
},
"pru": {
"value": 0,
"imagePath": "systems/pmtrpg/assets/PrudenceIcon.webp"
},
"jus": {
"value": 0,
"imagePath": "systems/pmtrpg/assets/JusticeIcon.webp"
},
"cha": {
"value": 0,
"imagePath": "systems/pmtrpg/assets/CharmIcon.webp"
},
"ins": {
"value": 0,
"imagePath": "systems/pmtrpg/assets/InsightIcon.webp"
},
"tem": {
"value": 0,
"imagePath": "systems/pmtrpg/assets/TemperanceIcon.webp"
}
}
},
"npc": {
"templates": ["base"]
}
},
As to whether it's in the "Roll Data" or not, i'm not too sure? I mean, i've been able to use it to have the system give me the ability modifier and roll a check based off of it. And as to the part where you say that Data Modles is preferred while template is deprecated, i'd love to update to Data Models! I just don't know where to- start? I followed the Foundry Wiki and it lead me down to Boilerplate, and when i downloaded Boilerplate and checked the wikis and such the very first thing i came across was this file formatting itself.
Forien
Forien•9mo ago
you need to modify the Actor#getRollData() to properly handle Roll Data. Other things you have probably work because they were in the boilerplate already Also I do not know what system you are making, but abilities is something that is more like dnd keyword, you should probably use term specific for your system (attribute, characteristic, stat etc.) to not confuse GMs and players
Ashby Blackburn
Ashby BlackburnOP•9mo ago
Lets see if i'm, getting this right. I changed the max in the templates base value back to "100" since it doesn't really matter, or well, it shouldn't given the fact that getRollData will replace it. So in template.json file, health looks like this:

"health": {
"value": 10,
"min": 0,
"max": 100
},

"health": {
"value": 10,
"min": 0,
"max": 100
},
Ahh, i see. That's in the actor.mjs file. It's still very much in it's template values form. Changing it up a bit, i think i'm on the right track? Though the change i made to the code in there doesn't seem to be affecting anything.
_getCharacterRollData(data) {
if (this.type !== 'character') return;

// Copy the ability scores to the top level, so that rolls can use
// formulas like `@str.mod + 4`.
if (data.abilities) {
for (let [k, v] of Object.entries(data.abilities)) {
data[k] = foundry.utils.deepClone(v);
}
}
const forAbility = data.abilities.for.value;
const healthFormula = 72 + (forAbility * 8);
data.health = {
value: 0,
min: 0,
max: healthFormula
};
// Add level for easier access, or fall back to 0.
if (data.attributes.level) {
data.lvl = data.attributes.level.value ?? 0;
}
}
_getCharacterRollData(data) {
if (this.type !== 'character') return;

// Copy the ability scores to the top level, so that rolls can use
// formulas like `@str.mod + 4`.
if (data.abilities) {
for (let [k, v] of Object.entries(data.abilities)) {
data[k] = foundry.utils.deepClone(v);
}
}
const forAbility = data.abilities.for.value;
const healthFormula = 72 + (forAbility * 8);
data.health = {
value: 0,
min: 0,
max: healthFormula
};
// Add level for easier access, or fall back to 0.
if (data.attributes.level) {
data.lvl = data.attributes.level.value ?? 0;
}
}
The part that i added is all that there is on the character roll data starting on const forAbility = data.abilities.for.value; all the way to the max: healthFormula parameter Though i wouldn't worry too much about responding to my query here, as i'm looking into the whole DataModels thing that you mentioned. Is there any resource or wiki that i could utilize to learn it?
Forien
Forien•9mo ago
I do not know too much about WIki. There is some information about it on Foundry's Knowledge Base. Otherwise you could take a look at DND 5e 3.0.0+, or at effect refactor branch of WFRP4e, as both systems switched/are switching to Data Models (other systems probably as well, but I'm not as familiar) I do not know about the method you showed, all I know is that Actor#getRollData() method should return an object of key-value pairs that will be used by rolls, where @something.is.here would be a something.is.here key/path in that object.
Ashby Blackburn
Ashby BlackburnOP•9mo ago
got you, many thanks for the help!
Want results from more Discord servers?
Add your server