Tutorial: a keeper with a request
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.