this post was submitted on 05 Oct 2025
4 points (100.0% liked)

ObsidianMD

4796 readers
2 users here now

Unofficial Lemmy community for https://obsidian.md/

founded 2 years ago
MODERATORS
 

I am trying to put together a D&D character sheet in obsidian using the dataview plugin. It is going well but I have run into the fact some stats which I want to display (e.g. AC) are a function of Ability Modifiers (e.g. Con of +3) which themselves are a function of the character's Ability Scores (e.g. Con of 16).

As far as I can see, dataview lets you define variables (properties) in the front matter of a page and then reference them on different pages, but I cant seem to find a way to define one of these variable as a function of other variables.

I have tried this kind of thing with no success:

---

con: 16

conmod: floor((number(this.con) - 10)/2)

ac: 10 + this.conmod

---

`=ac`

This video was super helpful but only got me so far... Any advice? Maybe this is just a limitation of dataview.

you are viewing a single comment's thread
view the rest of the comments
[โ€“] SkinList@lemmy.world 2 points 1 month ago* (last edited 1 month ago) (1 children)

Basically solved! Code is as follows. This requires dataview and numerals add-ons for obsidian. I think there is some weird behaviour with the floor function that should be at the start of the g(x) function but i would guess that it is because it isnt a function that numerals supports perhaps? I haven't looked at this yet.

--- numerals: all

strsco: 10

consco: 16

dexsco: 16

intsco: 10

wissco: 12

chasco: 8

---

```math

# define ability modifier calculation function

g(x) = (x - 10)/2

# ability scores are specified in the properties

# calculate the modifiers using the ability modifier function g(x)

@[strmod::0] = g(strsco)

@[conmod::3] = g(consco)

@[dexmod::3] = g(dexsco)

@[intmod::0] = g(intsco)

@[wismod::1] = g(wissco)

@[chamod::-1] = g(chasco)

# calculate AC

@[ac::16] = 10 + conmod + dexmod

```

AC is `=this.ac`

References:

Props to you for coming back and posting your solution.