Skip to documentation
CranberryClock.Ideas / Systems / Design

INDEPENDENT TOOL / v0.1.0

ChatterTutorial

Work through the Chatter example and adapt the pattern to your own project.

Tutorial: a keeper with a request

javascript
import { Conversation } from '@cranberry-forge/chatter';
import { mountDialogue } from '@cranberry-forge/chatter/dom';

const story = {
  id: 'keeper', start: 'hello', variables: { accepted: false, coins: 3 },
  nodes: {
    hello: {
      speaker: 'Mira', text: 'You have {{coins}} coins. Will you help?',
      choices: [
        { id: 'yes', text: 'Of course.', target: 'thanks', once: true,
          effects: [{ op: 'set', variable: 'accepted', value: true }] },
        { id: 'leave', text: 'Another time.', target: null }
      ]
    },
    thanks: { speaker: 'Mira', text: 'Then there is still a little light.' }
  }
};

// Call when a Three.js interaction selects an NPC.
const talk = new Conversation(story);
const box = mountDialogue(panelElement, talk, {
  onEnd() { movementEnabled = true; }
});
movementEnabled = false;
const unsubscribe = talk.subscribe(view => {
  quest.accepted = talk.variables.accepted;
});

// On scene cleanup:
box.dispose();
unsubscribe();

Movement, camera framing, voices, quests and inventory effects belong to your game. The runtime only executes the declared set and add operations on its own variables. It never evaluates scripts or looks up remote content.

View versioned source on GitHub ↗