Skip to content

How to play a campaign in your own program

These steps take a story from the editor into a program of yours: a game, an app, a page or a tool. Each step has a tab for each binding, and choosing a language once switches every tab on the page. What each call does, and every option it takes, is in the binding’s reference: JavaScript and TypeScript, C and C++, C#, Dart.

  1. Export the story as a campaign. In the editor, choose Export project in the project panel, choose Campaign, and export to a folder. The folder, with campaign.json at its root, is what your program opens. If your program will use the engine without Python, tick Needs no Python first. See How to export a project copy or a campaign.

  2. Add the binding.

    Terminal window
    npm install @ripplefx/player @ripplefx/soundscape

    Serve the campaign folder beside your page, and serve .wasm files as application/wasm. Your bundler copies the engine’s files from the package.

  3. Choose the variant, if the campaign needs no Python and you want the smaller engine.

    Nothing to do: Campaign.load reads the campaign’s manifest and loads the engine with Python only when the campaign needs it. Pass python: false to refuse one that does.

    The engine without Python refuses a campaign that needs it when the campaign is opened.

  4. Open the campaign, make a session, and wrap it in a player. Choose the seed yourself: the same seed and the same answers play the same story. Give the player your clock too, for a story that reads the time: it hands the story the time only once the reader has allowed it.

    import { Campaign, Player } from '@ripplefx/player';
    const campaign = await Campaign.load('/campaigns/the-city-of-elsenmar/');
    const player = new Player(campaign.session({ seed: BigInt(Date.now()) }), {
    onEffect: draw, // step 5
    onError: (error) => console.error(error),
    }); // the Player reads this machine's clock by itself

    A program that packs its assets its own way opens the campaign from its files in memory instead: Campaign.fromFiles, Campaign::open_files, Campaign.OpenFiles or Campaign.openFiles.

  5. Draw the turn. Every effect reaches your handler in order. The ones that need drawing are a passage (show), a form (ask), the question a story asks before it reads the clock or the reader’s position (permit, step 6) and an ending (ended, failed, stopped). Draw a choice that is not available greyed, and do not let it be pressed.

    function draw(effect: Effect) {
    switch (effect.kind) {
    case 'show': showPassage(effect.passage); break; // passage.text, passage.choices[i].available
    case 'ask': showForm(effect.prompt); break;
    case 'permit': askPermission(effect.kinds); break; // step 6
    case 'ended': showEnding(effect.title); break;
    case 'failed': showProblem(effect.message); break;
    }
    }

    A passage’s text is Markdown, or HTML when the campaign was exported that way, as the manifest’s text format says. Render it with a library of your choice.

    Draw each field of a form by its label, in the reader’s language, with its placeholder as the hint, and answer it under its name. Mark a field that is not optional as required, and do not submit it empty. Draw a field with options as a menu: one pick for a single value, any number for a list.

  6. Answer the question before the story begins. A story that reads the clock or the reader’s position asks first: its first turn is permit, naming the kinds still unanswered, and nothing else happens until each is answered. Answer each kind with the player’s permit; the last answer begins the story. On a yes to the location, fetch a position and hand it in before the permit that says yes, or the first page reads nothing. On a no, the reader may give a stand-in, a time or a place the story believes instead.

    player.setPosition({ latitude, longitude, accuracy }); // on a yes, before the permit
    player.permit('location', true);
    player.setStandIn('dateTime', '2026-10-31 23:00'); // on a no, if the reader typed one
    player.permit('dateTime', false); // the last answer begins the story

    If your program remembers the reader’s answers, give them before start, and the question is never shown. A save carries no answers, so answer a resumed session again.

  7. Start the story, answer the reader, and give the player your clock. Call the verb for what the reader did. Outside JavaScript, call the player’s update from your frame or event loop: it answers a wait once its time has come, and runs a passage’s countdown, beginning it and letting it run out. In JavaScript the player does both by itself.

    player.start();
    choiceButton.onclick = () => player.choose(index);
    leaveButton.onclick = () => player.choose(); // the reader leaves the passage
    form.onsubmit = () => player.answer({ name: 'Ada', calling: 'wizard' }); // an option by its id
    // The player waits out a hold by itself.

    A verb the story was not asking for is refused and nothing moves. Catch the refusal for a spent choice, for an unknown language and for a stand-in the reader typed that does not read, which are the ones met in ordinary use.

    To offer a reader no time limits, make the player with countdowns: false (countdowns = false in C++, Countdowns = false in C#): no countdown runs, and the story waits for the reader. Draw a countdown the author made visible from the player’s countdown state. How an author puts one on a choice is How to put a countdown on a choice.

  8. Register the author’s callbacks. Agree the names with the author. A handler must not call a verb, so queue one for after it returns.

    player.onCallback('chapterTwoBegan', (fired) => game.unlock('chapter-2'));
    player.onCallback('quitToTitle', () => queueMicrotask(() => player.stop()));
  9. Give the story a speaker. Make a soundscape driver over the campaign and a speaker, pass the driver to the player as its audio, and tick it with the player. In a browser, @ripplefx/soundscape is the speaker; elsewhere you implement the binding’s speaker interface over your own audio API, as its reference describes.

    import { Player, SoundscapeDriver } from '@ripplefx/player';
    import { WebAudioSpeaker } from '@ripplefx/soundscape';
    const speaker = new WebAudioSpeaker();
    const audio = new SoundscapeDriver(campaign, speaker);
    const player = new Player(campaign.session({ seed }), { onEffect: draw, audio });
    begin.onclick = async () => { await speaker.unlock(); player.start(); }; // sound needs a click first
  10. Save, and resume. Checkpoint while the story is on a passage or a form, and keep the save with the seed. To resume, open a session from the save over the same campaign and start it: it shows the saved turn again, after the question of step 6 if the story reads the world, and a timed passage waits afresh.

    const save = player.session.checkpoint(); // undefined except on a passage or a form
    const resumed = Session.resume(campaign, save, { seed });

    A save from a campaign that has since changed too much is refused when it is resumed. Tell the player the save is from an older build of the story. If the engine reports a trap, the campaign is unusable from then on: dispose of it, open it again, and resume from the last checkpoint.

  11. Ship the engine’s notice. Reproduce the engine’s NOTICE wherever your product lists its third-party software. Each binding names the file: ENGINE-NOTICE in the npm package, share/ripple_effect/ENGINE-NOTICE in a CMake install, ENGINE-NOTICE.txt in the C# engine packages, and the archive’s NOTICE for Dart.