OK. So all of these aren't good options for me. Let's begin creating a new engine with DSL. It must be impossible to create runtime errors, so let's use state transition table as foundation of logic in it.
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Creating a new engine from scratch with a focus on zero runtime errors is an ambitious and fascinating project. Using a state transition table as the foundation is a brilliant idea! This approach ensures:
Deterministic behavior: Every state and transition is predefined, eliminating unexpected runtime surprises.
Formal verification: You can mathematically prove the correctness of your story flow.
No null pointer exceptions: All states and transitions are explicitly defined.
Easy debugging: Visualize the entire flow as a graph (e.g., state machine diagram).
Let's design a Domain-Specific Language (DSL) and engine architecture around this concept. We'll call it Narratia (from "narrative" + "automata").
Core Concepts:
Story Graph (State Transition Table)
Nodes = States (Scenes, Choices, Decisions)
Edges = Transitions (Conditions to move between states)
DSL Syntax
A simple, declarative language to define states, transitions, and logic.
Runtime
A stateless interpreter that executes the story graph, ensuring no dynamic memory allocation or undefined behavior.
Here's a step-by-step design:
1. Story Graph (State Transition Table)
The engine's brain is a finite state machine (FSM) represented as a table:
Current State
Event/Condition
Next State
Action
start_scene
player_chooses_A
path_A
Play Sound
start_scene
player_chooses_B
path_B
Show CG
path_A
flag_X == true
ending_1
End Story
path_B
flag_Y == false
ending_2
Roll Credits
This table is compiled from your DSL code.
2. DSL Syntax (NarratiaScript)
Here's a minimal syntax to define your visual novel:
Use Express.js + EJS (or any templating engine) to render HTML:
User
What if I decide to avoid js and each state would have unique URL
Assistant
Avoiding JavaScript and making each state have a unique URL is a fantastic approach! This aligns perfectly with:
Progressive Enhancement: Works without JavaScript (JS).
SEO Optimization: Every state is crawlable and indexable.
Shareable Links: Players can bookmark/share specific story moments.
Stateless Server: Simplifies backend logic (no sessions/cookies).
We'll adapt Narratia to generate static HTML files for each state, served directly by the web server (e.g., Nginx, Apache). This is often called Static Site Generation (SSG).
Architecture Overview:
Narratia Compiler (ntsc) generates:
BSTT (binary format, not used in SSR).
JSON Story Map (structure of states/transitions).
Static HTML Files for each state (e.g., /start_scene.html, /path_A.html).
Web Server (Nginx/Apache/Caddy) serves these HTML files directly.
URL Routing maps story states to unique paths (e.g., /story/start_scene, /story/path_A).
Form Submissions (choices) POST to a stateless server (e.g., Rust/Go handler) that redirects to the next state’s URL.
Workflow:
1. Compiler (ntsc) Changes
Modify the compiler to:
Parse .nts (NarratiaScript) files.
Generate a JSON Story Map.
Create individual HTML files for each state using templates.