Skip to content

Commit 4e19551

Browse files
committed
add example: DnD 5e ability scores and modifiers
This example shows how to calculate values from frontmatter properties and store them in memory, than reusing and formatting them where needed.
1 parent 09d6371 commit 4e19551

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
STR: 8
3+
DEX: 16
4+
CON: 11
5+
INT: 12
6+
WIS: 14
7+
CHR: 11
8+
---
9+
10+
This example calculates a DnD character's ability modifiers from the ability scores and displays it all in a list.
11+
12+
The modifiers are stored in `memory` and not in the frontmatter. This reduces clutter but requires some hidden fields that calculate the values while the fields in the list just format the value to always contain a `+/-` sign.
13+
14+
15+
## Character ability scores
16+
17+
```meta-bind
18+
VIEW[ floor(({STR} - 10) / 2) ][math(hidden):memory^STR_mod]
19+
```
20+
```meta-bind
21+
VIEW[ floor(({DEX} - 10) / 2) ][math(hidden):memory^DEX_mod]
22+
```
23+
```meta-bind
24+
VIEW[ floor(({CON} - 10) / 2) ][math(hidden):memory^CON_mod]
25+
```
26+
```meta-bind
27+
VIEW[ floor(({INT} - 10) / 2) ][math(hidden):memory^INT_mod]
28+
```
29+
```meta-bind
30+
VIEW[ floor(({WIS} - 10) / 2) ][math(hidden):memory^WIS_mod]
31+
```
32+
```meta-bind
33+
VIEW[ floor(({CHR} - 10) / 2) ][math(hidden):memory^CHR_mod]
34+
```
35+
36+
- STR: `VIEW[**{STR}**][text(renderMarkdown)]` (`VIEW[ concat(isPositive({memory^STR_mod}) ? '+' : '', string({memory^STR_mod})) ][math]`)
37+
- DEX: `VIEW[**{DEX}**][text(renderMarkdown)]` (`VIEW[ concat(isPositive({memory^DEX_mod}) ? '+' : '', string({memory^DEX_mod})) ][math]`)
38+
- CON: `VIEW[**{CON}**][text(renderMarkdown)]` (`VIEW[ concat(isPositive({memory^CON_mod}) ? '+' : '', string({memory^CON_mod})) ][math]`)
39+
- INT: `VIEW[**{INT}**][text(renderMarkdown)]` (`VIEW[ concat(isPositive({memory^INT_mod}) ? '+' : '', string({memory^INT_mod})) ][math]`)
40+
- WIS: `VIEW[**{WIS}**][text(renderMarkdown)]` (`VIEW[ concat(isPositive({memory^WIS_mod}) ? '+' : '', string({memory^WIS_mod})) ][math]`)
41+
- CHR: `VIEW[**{CHR}**][text(renderMarkdown)]` (`VIEW[ concat(isPositive({memory^CHR_mod}) ? '+' : '', string({memory^CHR_mod})) ][math]`)

0 commit comments

Comments
 (0)