Get AI summaries of any video or article — Sign up free
Obsidian - Creating TTRPG Calculators with DataviewJS and ChatGPT thumbnail

Obsidian - Creating TTRPG Calculators with DataviewJS and ChatGPT

Josh Plunkett·
5 min read

Based on Josh Plunkett's video on YouTube. If you like this content, support the original creators by watching, liking and subscribing to their content.

TL;DR

Enable DataView’s JavaScript features by turning on both “Enable JavaScript queries” and “Enable inline JavaScript queries.”

Briefing

Tabletop RPG players can turn Obsidian into a quick-calculation workstation by embedding small “apps” inside notes using the DataViewJS plugin. The core idea is to build interactive calculators—like Pathfinder 2e jump distance, difficulty class (DC) thresholds, and even travel-time estimates—so players can enter a few numbers and get results instantly during play.

The walkthrough starts with a working jump distance calculator inside an Obsidian note. After installing DataView and enabling both “JavaScript queries” and “inline JavaScript queries” in DataView settings, the calculator appears as a button-driven interface. Enter a Strength value, press “calculate,” and the note outputs different jump distances for running long jump, standing long jump, and vertical jump variants. The calculator is designed to be reusable: the same note can be dragged into sidebars or kept alongside other tools, effectively acting like a plug-in panel inside the vault.

From there, the focus shifts to how these calculators are actually built. The jump calculator’s code defines input fields (for example, Strength), renders output text on the page, and uses a click event listener to compute results. It also includes a small housekeeping step—clearing prior output—so repeated button presses don’t keep appending duplicate results. The presenter emphasizes that the JavaScript involved is readable enough for non-experts to adapt, even if they can’t write it from scratch.

That’s where ChatGPT enters as a practical workaround for people who can’t code. Instead of manually writing DataViewJS from the ground up, the process is to copy a known working calculator’s code as a template, then ask ChatGPT to generate a new DataViewJS application for a specific RPG mechanic. A DC calculator example shows the workflow: paste ChatGPT-generated code into a new Obsidian note using the correct DataViewJS code block tags, then test it with sample inputs. When errors appear—such as issues with DV dot fragment—ChatGPT can be prompted with the exact error message to produce an updated version (for example, switching to db.div to create the needed container).

The transcript also highlights that results aren’t always perfect on the first attempt. Iteration matters: sometimes ChatGPT overwrites the wrong section, produces a non-working fragment, or requires more precise instructions (like explicitly setting a default level). Still, the overall payoff is significant: after roughly an hour and a half of back-and-forth, a more complex Pathfinder 2e travel calculator becomes functional. In that case, ChatGPT initially tried to use a lookup-table approach, but Obsidian/DataViewJS struggled with the needed query logic; switching to nested if-then conditionals made the calculator work.

The takeaway is less about any single calculator and more about a repeatable method: enable DataViewJS, start from a working template, use ChatGPT to generate or modify code for specific TTRPG rules, and verify calculations before trusting them at the table.

Cornell Notes

Obsidian can host interactive TTRPG calculators by using the DataViewJS plugin to render input fields, buttons, and computed results inside notes. After enabling “JavaScript queries” and “inline JavaScript queries,” a jump-distance calculator can be tested by entering Strength and clicking a calculate button to produce running/standing/vertical jump distances. For mechanics that require more logic—like Pathfinder 2e DCs and travel time—ChatGPT can generate DataViewJS code when given a working template and clear rule targets. The process often needs iteration, including fixing DataViewJS-specific errors (e.g., replacing DV dot fragment with db.div) and double-checking the math before using it in real sessions.

What setup steps make DataViewJS calculators work inside Obsidian notes?

Install and enable the DataView plugin, then open DataView settings and turn on both options: “Enable JavaScript queries” and “Enable inline JavaScript queries.” Without those toggles, DataViewJS code blocks won’t run as interactive calculators.

How does the jump-distance calculator behave when used during play?

It provides an input for Strength and a “calculate” button. Clicking the button computes and displays multiple jump outcomes: long jump with a running start, long jump from standing, high jump with a running start, and a standing high-jump variant. Repeated clicks clear and rewrite the output instead of endlessly appending new text.

Why does starting from a known working calculator matter when using ChatGPT?

DataViewJS syntax and Obsidian-specific rendering details are easy to get wrong. Using a working calculator as a template gives ChatGPT the correct structure (imports, input fields, button wiring, and output rendering). Then prompts can focus on the RPG mechanic change—like adding a DC calculator or adjusting defaults—rather than reinventing the whole framework.

What happens when ChatGPT-generated DataViewJS code fails, and how is it fixed?

When an error occurs (the transcript cites a failure involving “DV dot fragment”), the fix is to feed the exact error back into ChatGPT. In the example, ChatGPT updates the approach by using db.div to create the container for import fields, buttons, and results, producing a version that runs.

How was the Pathfinder 2e travel calculator made to work despite initial complexity?

ChatGPT initially attempted a lookup-table approach, but DataViewJS couldn’t handle the needed query/table logic in the note environment. The solution was to replace the table logic with nested if-then statements that evaluate conditions and compute travel time directly. After that shift, the travel calculator produced outputs like travel time for a given distance and hours per day.

What practical guidance is given for trusting calculator outputs?

Even when a calculator runs “straight out of the box,” the math should be verified. The transcript recommends challenging ChatGPT with corrections if results seem wrong and double-checking calculations before relying on them during sessions.

Review Questions

  1. What DataView settings must be enabled to run interactive JavaScript inside Obsidian notes?
  2. Describe the iterative workflow for generating a new DataViewJS calculator with ChatGPT when errors occur.
  3. Why might a lookup-table strategy fail in DataViewJS, and what alternative logic approach can work instead?

Key Points

  1. 1

    Enable DataView’s JavaScript features by turning on both “Enable JavaScript queries” and “Enable inline JavaScript queries.”

  2. 2

    Build calculators as note-embedded mini-apps: input fields collect values, a button triggers computation, and output text is rendered on the page.

  3. 3

    Use a known working DataViewJS calculator as a template so ChatGPT can generate correct Obsidian/DataViewJS structure rather than starting from scratch.

  4. 4

    When code fails, copy the exact error message and prompt ChatGPT to revise the implementation (for example, switching from DV dot fragment to db.div).

  5. 5

    Expect iteration: ChatGPT may overwrite the wrong defaults or produce non-working code unless prompts are specific and testing is repeated.

  6. 6

    For complex Pathfinder 2e logic, nested if-then conditionals can be more reliable than lookup-table approaches in DataViewJS.

  7. 7

    Treat calculator outputs as unverified until checked, and re-prompt ChatGPT if the results don’t match the rules.

Highlights

A DataViewJS calculator can behave like a reusable sidebar tool: drag the note into a bar and enter values during play.
Repeated button clicks can be handled cleanly by clearing prior output before writing new results.
Feeding the exact DataViewJS error back into ChatGPT can produce targeted fixes, such as replacing DV dot fragment with db.div.
Nested if-then logic can replace lookup tables when DataViewJS query/table handling becomes unreliable.
Even “working” AI-generated code should be double-checked before trusting it at the table.

Topics

Mentioned