Quest authoring preview

Author a quest

DDQ quests are JSON documents. A definition names the actors, state, dialogue, conditions, and ordered actions that make one quest work.

Start a quest definition

Start with one complete JSON object. Keep the first quest small enough to follow from its start hook to its completion action.

  1. Set schemaVersion to the number 1.
  2. Choose exclusive or concurrent quest behavior.
  3. Choose a globally unique questName.
  4. Add named resources as objects. Use arrays only where order matters.
  5. Define the required hooks for the quest and each NPC.
  6. Add at least one reachable call to complete_quest.

The following example spawns an archivist, opens a dialogue, records the player's answer, and completes the quest:

{
  "schemaVersion": 1,
  "type": "exclusive",
  "questName": "archivist_invitation",
  "positions": {
    "archivist_start": {
      "type": "random_room"
    }
  },
  "npcs": {
    "archivist": {
      "display_name": "The Archivist",
      "initialState": {
        "accepted": {
          "type": "boolean",
          "default": false
        }
      },
      "solid": true,
      "opaque": false,
      "sprites": {},
      "dialogs": {
        "invitation": {
          "text": "Will you preserve what we found?",
          "portrait": "placeholder",
          "onAbort": "noop",
          "choices": [
            {
              "text": "I will.",
              "action": {
                "action": "call_function",
                "functionName": "accept_invitation"
              }
            }
          ]
        },
        "archivist_busy": {
          "text": "The Archivist is speaking with someone else.",
          "portrait": "placeholder",
          "onAbort": "noop"
        }
      },
      "functions": {
        "on_interact": [
          {
            "action": "claim_quest_for_interactor"
          },
          {
            "action": "dialog",
            "dialogId": "invitation"
          }
        ],
        "on_busy": [
          {
            "action": "dialog",
            "dialogId": "archivist_busy"
          }
        ],
        "accept_invitation": [
          {
            "action": "set_state",
            "stateRef": "accepted",
            "value": true
          },
          {
            "action": "complete_quest"
          }
        ]
      }
    }
  },
  "functions": {
    "on_start": [
      {
        "action": "spawn",
        "targetName": "quest.archivist",
        "position": "quest.archivist_start"
      }
    ],
    "on_complete": [
      {
        "action": "despawn",
        "targetName": "quest.archivist"
      }
    ]
  }
}

An empty sprites object is valid, but it produces no automatic NPC graphics. Add registered sprite identifiers before you playtest the quest.

Quest definition fields

Named collections use object keys as resource names. Function actions, dialogue choices, and composite condition operands use arrays because their order matters.

FieldStatusPurpose
schemaVersionRequiredUse the JSON number 1. Numeric strings are invalid.
typeRequiredUse exclusive for one owner or concurrent for per-player progress.
questNameRequiredGlobally unique quest name.
initialStateOptionalTyped quest state declarations and their default values.
npcsOptionalNamed interactive NPC definitions.
hostilesOptionalNamed hostile mob templates. Each key can produce one mob.
itemsOptionalNamed quest items minted when the quest attaches.
positionsOptionalNamed floor anchors resolved when the quest attaches.
dialogsOptionalNamed quest-level dialogues.
conditionsOptionalNamed quest-level conditions.
timersOptionalUnique quest-level timer names. Required when set_timeout or cancel_timeout is used.
functionsRequiredNamed action lists, including on_start and on_complete.

Quest types

Set the required top-level type to exclusive or concurrent. The value controls ownership, state, timers, interaction, and completion behavior. It is not descriptive metadata.

Exclusive quests

An exclusive quest belongs to one character and can complete only once. Its quest and NPC state must be scalar, so do not use keyed: true declarations.

Call claim_quest_for_interactor from an NPC interaction flow before any player-driven completion path. The first claim permanently stores that character in the read-only quest.locked_to_character property. A repeat claim by the owner is a successful no-op. Other characters are routed to the NPC's on_busy function.

{
  "type": "exclusive",
  "functions": {
    "accept_quest": [
      { "action": "claim_quest_for_interactor" },
      { "action": "call_function", "functionName": "show_briefing" }
    ]
  }
}

Concurrent quests

A concurrent quest has no single owner. Every quest and NPC state declaration must use keyed: true, and the quest cannot call claim_quest_for_interactor. Each player keeps independent progress.

A timer scheduled with an interactor is also independent for that character. Concurrent completion records the floor's first completion, but the quest remains active. Later players can complete it and run on_complete for their own progress.

State

Every quest-level and NPC-level initialState entry is a typed declaration. A state property's type does not change during the quest. Hostile templates do not have quest state.

String, number, boolean, UUID, and position declarations contain exactly type and default, plus optional keyed: true. An enum declaration also contains values.

TypeRequired defaultRuntime values
stringAny JSON stringJSON strings
numberAny finite JSON numberFinite JSON numbers
booleantrue or falsetrue or false
player_uuidnullnull or an RFC 4122 player UUID
npc_uuidnullnull or an RFC 4122 quest NPC or mob UUID
position[x, y, z]A three-element safe-integer position tuple
enumOne declared memberThe declared member set
{
  "initialState": {
    "visit_count": {
      "type": "number",
      "default": 0
    },
    "warning_scheduled": {
      "type": "boolean",
      "default": false
    },
    "claimed_player_id": {
      "type": "player_uuid",
      "default": null
    },
    "last_position": {
      "type": "position",
      "default": [0, 0, 0]
    },
    "route": {
      "type": "enum",
      "values": ["unclaimed", "active", "rewarded"],
      "default": "unclaimed"
    }
  }
}

Assignments must preserve the declared type. Player and NPC UUIDs are not interchangeable. Player substitutions require player_uuid state, mob substitutions require npc_uuid state, and counter actions require number state.

A boolean default or literal assignment must be true or false. DDQ does not convert strings such as "true" or numbers such as 0 and 1 into booleans.

Enum values must be a non-empty array of unique tokens. Each token starts with a lowercase letter and may contain lowercase letters, numbers, and underscores. The default must be one of those tokens.

Assign an enum from a declared member or from another enum with exactly the same member set. Member order does not affect compatibility. An enum is distinct from string, even when both contain the same text.

Raw initial values, inferred types, arbitrary objects or arrays, and empty objects used as UUID-keyed maps are invalid. The values field is valid only on enum declarations.

Store state by UUID

Add keyed: true to store one independent value per player or NPC UUID. The scalar type and default apply to every member. A missing member reads as the declaration default without creating a persisted value.

Address a keyed member with one terminal UUID substitution, such as quest.progress.[[interactor]]. The selector must resolve to player_uuid or npc_uuid. Dialogue choice writes must use [[interactor]].

{
  "initialState": {
    "progress": {
      "type": "number",
      "default": 0,
      "keyed": true
    }
  }
}

Names and scope

Use lowercase ASCII letters and underscores for every authored name. Do not use digits, spaces, hyphens, or punctuation. This rule applies to resource keys, state keys, questName, and timerName.

A questName must be globally unique. The name is also reserved across every resource and state key in every quest. Other resource names can repeat in separate NPC scopes.

Within a quest, NPCs, hostiles, items, positions, dialogues, conditions, and functions share one resource namespace. A quest-level position cannot have the same name as a quest-level state property.

Reserved timer names belong to the quest-level namespace. A timer name cannot duplicate another quest-level resource or state name.

Prefer a name such as player_has_archive_key over a generic name such as check. A specific name makes reference errors easier to find.

Named positions

A position describes a placement relationship, not a fixed coordinate. DDQ resolves each position when the quest attaches to a completed floor and persists the result.

TypeRequired fieldsResolution
randomNoneSelects a valid anchor anywhere on the quest floor.
random_roomNoneSelects an eligible room, then a valid anchor inside it.
random_in_roompositionRefSelects an anchor in the room that contains positionRef.
random_in_other_roompositionRefSelects an anchor in a different eligible room.
random_reachablepositionRefSelects an anchor connected to positionRef by cardinal movement.
random_nearpositionRef, distanceSelects an anchor within the inclusive Chebyshev distance range.
relativepositionRef, offsetAdds an exact [x, y] offset to positionRef.

Use positionRef with every dependent position type. A random_near position also requires an inclusive [minimum, maximum] distance. A relative position requires an exact [x, y] offset.

Position selection is deterministic. Temporary occupancy does not change the saved anchor. A later spawn action finds the nearest open tile if the anchor is occupied.

Exclude secret rooms and vaults

Every random position type accepts the optional boolean fields not_in_secret and not_in_vault. Both default to false. Set a field to true to exclude coordinates in secret rooms or sealed vaults. This applies to random, random_room, random_in_room, random_in_other_room, random_reachable, and random_near. The relative position type accepts neither field.

DDQ first builds the candidate set using the position's spatial, reference, reachability, distance, and occupancy rules. It then removes candidates that the enabled filters exclude. Coordinates outside every room remain eligible. If no legal candidate remains, the quest cannot attach to the floor.

{
  "positions": {
    "fallback_room": {
      "type": "random_in_other_room",
      "positionRef": "quest.battle_center",
      "not_in_secret": true,
      "not_in_vault": true
    },
    "reachable_public_tile": {
      "type": "random_reachable",
      "positionRef": "quest.battle_center",
      "not_in_secret": true
    }
  }
}

Actors and items

Quest NPCs

Every NPC requires display_name, initialState, sprites, and functions. Its functions must include on_interact and on_busy.

NPCs are solid and opaque by default. The optional automatic sprite slots are spawn, idle, walk, interact, and despawn. You can also declare named sprite variants for set_npc_sprite actions.

A set_npc_sprite action names a quest NPC with targetName and declares a mode. The selected sprite must be registered and must appear in the target NPC's sprites object.

Use one_shot for a transient animation. It accepts an optional opacity from 0 through 100 and does not accept slot. Use replace with one automatic slot to replace that mapping for the rest of the quest. Replacement mode does not accept opacity.

{
  "action": "set_npc_sprite",
  "targetName": "quest.archivist",
  "mode": "replace",
  "slot": "idle",
  "sprite": "archivist/idle_wounded"
}

Hostile templates

Every hostile requires mob_type, display_name, and a positive integer level. Optional hp is a percentage from 0 through 100. The ordinary mob runtime owns combat, movement, damage, and death after the hostile spawns.

Omit sprites to use the mob's catalog graphics. If you provide overrides, include every sprite slot required by that mob type.

Quest items

A quest-mechanic item uses display_name and sprite. A catalog reward uses catalogId, level, and optional quantity. Do not mix the two shapes.

Each item key identifies one pre-generated item or stack. Once an action transfers the item, ordinary inventory and drop rules own it. Quest NPCs cannot receive items or gold.

Dialogue

Every dialogue requires text, portrait, and onAbort. The portrait must name registered portrait artwork. Set onAbort to noop when the quest needs no recovery. Without a choices array, DDQ supplies one OK response.

A choice contains text and one action. Choice actions can call a function, set one state value, or display another dialogue. Use a named function when one choice must perform several actions.

The dialog action must be the final action in its function. A synchronous dispatch that can reach dialog and would otherwise return to the next action must also be final in its caller. DDQ follows that rule through every function in the call chain.

Closing the dialogue, disconnecting, or dying before a choice or confirmation invokes onAbort once. Choices and abort handlers start later events, so their calls do not continue the function that opened the dialogue.

Target a player

A dialog action addresses one player. Omit targetRef to target the current interactor, or provide a reference that resolves to one player. An omitted target does not broadcast quest-level dialogue.

{
  "action": "dialog",
  "dialogId": "winning_result",
  "targetRef": "ddq.players.[[quest.player_id]]"
}

The registered placeholder portrait renders as a temporary black portrait box while final artwork is unavailable.

Conditions

Conditions are named, side-effect-free queries. Composite conditions evaluate from left to right and stop as soon as their result is known.

TypeRequired propertiesResult
trueNoneAlways returns true.
falseNoneAlways returns false.
compareopA, opB, operationCompares operands with eq, ne, gt, lt, gte, lte, or posIs.
item_countinventoryRef, itemNameChecks whether an inventory contains a named quest-mechanic item.
goldinventoryRef, amountChecks whether an inventory contains enough gold.
allconditionsReturns true when every named child condition is true.
anyconditionsReturns true when at least one named child condition is true.
noneconditionsReturns true when no named child condition is true.
is_player_presentplayerIdRefChecks whether stored player_uuid state identifies a living player on this floor.
within_rangeopA, opB, rangeChecks whether two same-floor positions are within an inclusive Euclidean tile radius.

The eq and ne operations can compare boolean values or compatible enum state values. They can also compare an enum with a string literal that belongs to that enum. Other string literals are invalid. The ordering operations and posIs accept neither boolean nor enum operands.

The string random produces a fresh integer from 0 through 99 when DDQ evaluates a comparison or assigns state. A bounded random expression selects a uniform integer from 0 through an inclusive, non-negative safe-integer maximum. Use it only as a compare operand or as set_state.value:

{
  "type": "compare",
  "opA": {
    "random": {
      "maximum": 5
    }
  },
  "opB": 0,
  "operation": "eq"
}

The example performs a fresh one-in-six check. A skipped composite branch consumes no random draw.

is_player_present reads a stored player UUID through playerIdRef. It returns true only when that UUID belongs to a living player in the active roster on the quest's floor. A null value, death, disconnection, dungeon exit, or floor change returns false without changing state.

playerIdRef must point to declared quest or NPC state. It does not accept an actor target, an interactor reference, or a player substitution.

{
  "type": "is_player_present",
  "playerIdRef": "quest.claimed_player_id"
}

Check a position range

within_range compares two position references on the same floor. It uses the same inclusive Euclidean tile radius as spell targeting. A range of 4 is true when dx² + dy² <= 16. It does not require line of sight or a reachable path.

Positions on different floors return false. If a runtime-backed position is unavailable, the condition emits a structured warning and follows the ordinary false branch.

{
  "type": "within_range",
  "opA": "interactor.position",
  "opB": "quest.guide.position",
  "range": 4
}

Functions and actions

A function is a named, ordered list of one to 16 actions. Functions return no values. Use declared state to carry information between them.

Function calls and condition branches return to the next action in their caller. An onFailure branch does not return. It runs its handler and discards the remaining actions in the failed function.

If a returning synchronous call or branch can open a dialogue, put that dispatch last in its function. This rule follows direct and indirect calls, including every possible switch case and random outcome.

ActionRequired fieldsEffect
check_conditionconditionName, onTrue, onFalseBranch after evaluating a named condition.
call_functionfunctionNameCall an authored function or the magic noop or complete_quest function.
switch_functionstateRef, casesCall the function mapped to the current member of declared enum state.
random_functionoutcomesSelect and call one function using positive integer weights.
apply_bufftargetRef, effectIdApply a registered effect to a player or quest hostile.
give_itemitemName, targetRef, onFailureMove one hidden quest item to a player or hostile.
take_itemsourceRef, itemName, onFailureRemove and destroy one quest-mechanic item.
give_goldtargetRef, amountGive a positive integer amount of gold.
take_goldsourceRef, amount, onFailureRemove a positive integer amount of gold or follow onFailure.
dialogdialogIdOpen one dialogue session. An optional targetRef selects one player. This action and any returning synchronous dispatch that can reach it must be last.
set_statestateRef and value or sourceRefWrite a static value or copy a sourceRef into declared state.
spawntargetName, positionSpawn one quest NPC or hostile near a resolved position.
despawntargetNameRemove one living quest NPC or hostile from the floor.
add_story_texttext, positionRefSend story text to players who can see a position.
set_npc_spritetargetName, mode, sprite; slot for replacePlay a one-shot NPC sprite or replace an automatic sprite slot.
set_player_healthtargetRef, percentageSet one living player to 1 through 100 percent of current maximum health.
navigate_topositionRef, onArrivalStart best-effort movement for the quest NPC that owns the function. This action is terminal.
claim_quest_for_interactorNonePermanently claim an exclusive quest for the current interactor.
increment_statestateRefAdd exactly 1 to declared number state.
decrement_statestateRefSubtract exactly 1 from declared number state.
complete_questNoneMark the quest complete and invoke on_complete once.
set_timeouttimerName, functionName, ticksSchedule a function in a reserved timer slot, then continue with the next action.
cancel_timeouttimerNameCancel the active timer in a reserved quest-level slot.

The engine rejects direct and indirect function cycles. At runtime, one causal chain can make at most eight function calls and can dispatch at most two reactive state-change waves.

React to one state property

Add on_state_change as a mapping from state property names to action arrays. Each key must name state declared by the same quest or NPC. You can map any subset of the owner's properties.

A hook runs after the originating execution commits and reads the new state. Its complete synchronous call chain is read-only and cannot use set_state, increment_state, or decrement_state. Timer callbacks and later dialogue events start fresh writable executions.

A keyed state hook runs separately for each changed UUID member and exposes that member as the uuid selector during its synchronous call chain. Scalar state hooks do not expose uuid.

{
  "functions": {
    "on_state_change": {
      "progress": [
        { "action": "call_function", "functionName": "show_progress_effect" }
      ]
    }
  }
}

Navigate a quest NPC

navigate_to may appear only in a function owned by a quest NPC. It moves that NPC toward a position with the ordinary cardinal, tile-by-tile movement rules. The action is terminal, so onArrival is its only continuation and runs later without an interactor.

The engine resolves and persists the destination when navigation starts. It replans when the next step becomes blocked and concludes on the closest reachable tile when the exact destination is occupied or unreachable. Best effort counts as arrival.

While moving, the NPC does nothing else and ignores every interaction attempt. Starting navigation closes its open dialogue sessions and runs each dialogue's onAbort once. A later navigation request replaces the earlier request without calling the earlier onArrival function.

{
  "action": "navigate_to",
  "positionRef": "quest.exit_position",
  "onArrival": "quest.after_arrival"
}

Reserve timer names

Before any function uses set_timeout or cancel_timeout, reserve its timer name in the quest's top-level timers array. The array defines timer slots but does not start them. Functions owned by NPCs and hostiles use the same quest-level list.

Each name must be unique and contain only lowercase letters and underscores. Setting an occupied slot replaces its active timer. Other reserved slots continue independently.

{
  "timers": [
    "warning_timer",
    "npc_departure"
  ]
}

Schedule a function

set_timeout records or replaces a named timer, then continues with the next action. The target function runs after the positive number of ticks in ticks. A timer callback starts a later execution, so a callback that opens a dialogue does not make set_timeout terminal.

[
  {
    "action": "set_timeout",
    "timerName": "warning_timer",
    "functionName": "show_warning",
    "ticks": 10
  },
  {
    "action": "set_state",
    "stateRef": "quest.warning_scheduled",
    "value": true
  }
]

Set player health

set_player_health sets one living player's current health to 1 through 100 percent of that player's current maximum. Its targetRef must be interactor or a player UUID substitution. The action does not accept a random player, an omitted target, or an onFailure branch. It cannot revive a dead player.

{
  "action": "set_player_health",
  "targetRef": "interactor",
  "percentage": 100
}

Change numeric state

increment_state adds exactly 1 to declared number state. decrement_state subtracts exactly 1. Neither action accepts an amount, coerces a value, or targets state declared with another type.

{
  "action": "increment_state",
  "stateRef": "quest.visit_count"
}

Route by enum state

switch_function reads one enum state value and calls the function assigned to that member. Its cases object must contain every member of the enum exactly once and cannot contain other keys. There is no default or fallthrough case.

stateRef must resolve to readable quest- or NPC-owned enum state. Literals, magic properties, random values, and string state are invalid switch sources. An out-of-domain runtime value is a persistence error rather than a no-op.

The action reads state once and calls the selected function synchronously. Execution returns to the next action in the caller. Multiple enum members may call the same function.

{
  "action": "switch_function",
  "stateRef": "quest.route",
  "cases": {
    "unclaimed": "show_intro",
    "active": "show_progress",
    "rewarded": "show_epilogue"
  }
}

Choose a weighted function

random_function selects one function from an ordered array of at least two outcomes. The action contains only action and outcomes. Each outcome contains exactly a positive safe-integer weight and a functionName. The total weight must also be a safe integer.

Weights are relative and do not need to total 100. Repeated function targets are valid, and their probabilities add. An outcome's probability is its weight divided by the total weight. The authored outcome order is part of deterministic replay. At runtime, the action consumes one random draw, never rerolls, and does not store its selection. Validation does not draw from the dungeon's random stream.

{
  "action": "random_function",
  "outcomes": [
    { "weight": 1, "functionName": "house_result" },
    { "weight": 18, "functionName": "losing_result" },
    { "weight": 18, "functionName": "winning_result" }
  ]
}

Every switch case and random outcome is a possible function-call edge. Validation follows all of them when it checks references, cycles, execution context, read-only closures, dialogue aborts, call budgets, and completion paths. Only the selected function executes at runtime and consumes one function call.

References

The field that contains a reference determines what the reference can target. For example, conditionName must resolve to a condition, while stateRef must resolve to declared writable state.

FormMeaning
<name>Use a resource owned by the current quest, NPC, or hostile.
npc.<name>Use a resource or property on the current quest actor.
quest.<name>Use a resource or state value on the current quest.
quest.<actor>.<name>Use a resource or property on another actor in this quest.
ddq.<quest>.<name>Use a resource on another attached quest on the same floor.
interactor.<property>Read a property from the player in the current interaction.
ddq.players.[[quest.player_id]].<property>Look up a player by a UUID stored in quest state.
ddq.mobs.[[quest.mob_id]].<property>Look up a mob by a UUID stored in quest state.
ddq.players.random.<property>Select a random living player on this quest floor.
ddq.mobs.random.<property>Select a random living mob on this quest floor.
<state>.[[<uuid_source>]]Read or write one member of UUID-keyed state through a player_uuid or npc_uuid source.

Use double brackets for one UUID substitution component, such as player_choices.[[interactor.id]]. Literal UUIDs are invalid in authored references.

Read-only magic properties include id, display_name, position, hp, presence, and alive where they apply. A quest also exposes z and complete. An exclusive quest also exposes its owner through locked_to_character.

The reserved uuid source is available only inside the synchronous call chain of a keyed on_state_change hook. Use it as a UUID substitution selector, not as a dotted reference root.

Validate a quest

DDQ validates the complete definition before it changes a floor. A failure rejects the whole quest. Check the following rules before you submit a definition:

  • Use only recognized fields and the exact JSON value type each field requires.
  • Set type to exactly exclusive or concurrent.
  • Use named objects for resources and non-empty arrays for functions.
  • Use not_in_secret and not_in_vault only on random positions, and give each field a boolean value.
  • Declare every state key with a type and default before an action writes to it.
  • Keep every state assignment compatible with the declared type.
  • Use scalar state for exclusive quests and keyed: true state for concurrent quests.
  • Give an exclusive quest a reachable claim_quest_for_interactor before any player-driven completion path.
  • Use only true or false as boolean defaults and literals.
  • Give every enum a unique, non-empty member list and use one declared member as its default.
  • Map every enum member in switch_function.cases, with no extra or fallback case.
  • Give random_function at least two outcomes with positive safe-integer weights and valid function references.
  • Map on_state_change only to state owned by the same quest or NPC, and keep its synchronous call chain free of state writes.
  • Resolve every function, condition, dialogue, item, actor, position, and state reference.
  • Keep condition and function call graphs free of cycles.
  • Put dialog and every returning synchronous dispatch that can reach it last in its function. Put navigate_to last in its owning NPC function. A set_timeout action can have actions after it.
  • Reserve every set_timeout and cancel_timeout timer name in the owning quest's top-level timers array.
  • Give every dialogue a registered portrait and an onAbort function.
  • Give every give_item, take_item, and take_gold action an onFailure function.
  • Make at least one completion path reach complete_quest.
  • Perform all desired cleanup inside on_complete.

There is no public submission endpoint yet. Keep each definition as one complete JSON document while the authoring and playtest workflow is built.