Larch Visual Novel Maker

Extensions

Web game cards and the game API: Unity WebGL and HTML5 games in your work

Upload a Unity WebGL or HTML5 game as a card and play it inside your work. This is also the full game API reference: playing cards, variables, items, portraits and AI replies, from JavaScript, Unity C# and HTTP.

Web game cards and the game API: Unity WebGL and HTML5 games in your work

A web game card puts a Unity WebGL build or any HTML5 game inside your Larch work, playable on the page like on itch.io. The story reaches the card, the game plays, and the story carries on. The game can call Larch back too: play dialogue, jump to a card, change variables, hand out items, show portraits, and let a character answer with AI.

Uploading a game

  1. Pick the Web game card from the whiteboard's add menu.
  2. Open the card and drop the game's zip in, or press upload. A single .html file works too.
  3. Wait while it is checked, extracted and stored. A large game takes a minute or two.

Rules for the zip:

  • It needs an index.html, at the top level or inside the one folder you zipped. Larch finds it.
  • Up to 500 MB and 1,000 files after extraction, 200 MB per file, paths up to 240 characters. These match itch.io's limits.
  • Plain zip (deflate) only. Password-protected zips, .rar and .7z are not accepted.
  • Keep file names to letters and digits. Non-ASCII names turn to gibberish in some zip tools, and the game then cannot find the file.

Uploading again makes a new build, and the card points to the new one. A published work keeps playing the build it was published with until you publish again.

Building with Unity

  1. File → Build Profiles (Build Settings in older versions), choose Web (WebGL), press Build.
  2. Zip the whole folder the build produced. It holds index.html, Build and TemplateData.
  3. Upload that zip.

Suggested Player Settings:

  • Publishing Settings → Compression Format: Brotli or Gzip both work; Larch serves them with the right headers. Decompression Fallback is not needed.
  • Resolution and Presentation → Run In Background: on, so the game does not freeze completely while Larch plays dialogue over it.
  • Splash Image → Show Splash Screen: turn it off here to drop the engine's Made with Unity splash. Unity 6 Personal can too.

Card settings

Screen

  • Fill the stage: the game follows the window. Unity's default template is switched to fill, and its footer is tucked away.
  • Fixed size: laid out at the game's own width and height, then scaled to fit. Choose this for games designed for one size.
  • Cover: shown on the whiteboard card and while the game loads.
  • Fullscreen button: lets players put the whole player in fullscreen.

Remove the Unity logo

Unity games get one more switch. When it is on, Larch takes the Unity logo out of the loading screen and the footer as it serves the game's page.

It removes the logo in the page template. The Made with Unity splash the engine draws after loading is not in the page: turn off Show Splash Screen in Unity's Player Settings.

Parameters

Parameters are values the card hands to the game, a name and a value each. Put card IDs, item IDs and character names here so the game hard-codes nothing, and one build can serve several cards.

  • JavaScript: Larch.params.dialogueCard
  • Unity: Larch.Param("dialogueCard")

The menu at the end of each row picks a card and fills in its ID.

Exits

A card normally has one line leading on. If the game can end in more than one way, add an exit for each, for example win and lose. Each exit adds a dot on the right of the whiteboard card; draw a line from it to the card that follows.

The game calls Larch.complete("win") to leave through that dot. With no name, an exit that is not linked, or the player pressing Continue the story, the card's ordinary line is followed.

What the game may use

  • Play cards, jump to cards, read their lines: on by default.
  • Read and write the story's variables: on by default.
  • Give and take the player's items: on by default.
  • Let characters answer with AI: off by default, because it uses AI allowance.

A call to anything unticked is answered with not-allowed.

Safety

  • The game runs in an isolated frame. It cannot reach the player's Larch account, sign-in or saves, and it cannot open windows, download files or navigate the page away.
  • A game's address only plays inside a work; opening it directly in the address bar is refused.
  • Every file is checked on upload. Executables and scripts (.exe, .dll, .apk, .sh and the like) are left out, even when renamed.
  • Zip bombs (archives that extract larger than they claim) are refused.
  • A game that carries a Larch Agent Key is refused. An Agent Key can edit the projects in your account, and game files are public to every player.
  • Well-known secret keys of other services (OpenAI, AWS, Stripe, GitHub, Discord webhooks and so on) are listed on the card so you can rotate them.

A game played on Larch needs no key at all. It talks straight to the player, which knows which work and which player this is.

The game API at a glance

One set of features, three ways to use it:

  • An HTML5 game played on Larch: the page already has window.Larch. Nothing to include.
  • A Unity game played on Larch: add Larch.cs and Larch.jslib to the project and call it from C#.
  • Outside Larch (the Unity Editor, builds for other platforms): call the HTTP API with the project API Key. It reads data and asks for AI replies.

Outside Larch there is no player, so jumping to cards, variables and items, which belong to a player's progress, exist only on Larch.

JavaScript API

Every method returns a Promise. On failure the Promise is rejected and error.message is one of the error codes listed below.

Outside Larch there is no window.Larch, so check first:

if (window.Larch) {
  await Larch.ready;
}

Basics

const info = await Larch.ready;
// { cardId, projectId, locale, playerName, embedded: true }

Larch.params.dialogueCard   // the card's parameters (strings)
Larch.paused                // true while Larch covers the game

Story

// Pause the game, play this card and what follows it over the game, then come back
await Larch.playCard(cardId);

// Leave the game; the story continues at this card (it may be on another whiteboard)
Larch.goToCard(cardId);

// The game is over: follow the card's ordinary line
Larch.complete();

// The game is over: leave through a named exit
Larch.complete('win');

The card given to playCard has to be on the same whiteboard as the game card. While it plays, the game's picture stays underneath, and the dialogue box, portraits and choices are drawn over it. When that chain has no next card, or links back to the game card, the game goes on.

Variables

const coins = await Larch.getVariable('coins');   // null when there is no such variable
await Larch.setVariable('coins', 12);             // a string, a number, true or false
const all = await Larch.getVariables();           // { name: value, … }

Variables are kept with the player's save. Writing progress into variables is the dependable way to have it there next time.

Items

const items = await Larch.getItems();
// [{ id, name, description, iconUrl, count }], count is how many the player holds

await Larch.giveItem('key', 1);   // an item's ID or name, from the project's item library
await Larch.takeItem('key', 1);

Lines and portraits

// Show one line in the work's own dialogue box; it continues when the player clicks
await Larch.say('The door will not open.');
await Larch.say('Leave it to me.', { character: 'Mana', emotion: 'happy' });

// Portraits: position is left, center or right
await Larch.showPortrait('Mana', { emotion: 'happy', position: 'right' });
await Larch.hidePortrait('Mana');
await Larch.hidePortrait();       // all of them

character takes a character's ID or name. emotion matches an expression in the character's expression library; when none matches, the main portrait is used.

Reading project data

const card = await Larch.getCard(cardId);
// {
//   id, title, type, boardId, nextCardId,
//   lines: [{ speaker, characterId, text, emotion, portraitUrl, voiceUrl }],
//   choices: [{ id, text, nextCardId }]
// }

const cards = await Larch.getCards();            // each card's id, title and type, without lines
const characters = await Larch.getCharacters();
// [{ id, name, role, summary, portraitUrl, expressions: [{ id, name, emotion, imageUrl }] }]

To draw dialogue inside the game yourself, take the lines, portraits and voice URLs from getCard.

AI replies

const answer = await Larch.aiChat('Mana', 'What do you think is behind this door?');
// { reply: '…', emotion: 'curious' }

// Ask with the conversation so far (up to 12 messages)
await Larch.aiChat({
  character: 'Mana',
  messages: [
    { role: 'user', content: 'Hello' },
    { role: 'assistant', content: 'Hello there.' },
    { role: 'user', content: 'Could you open the door for me?' },
  ],
});

The card has to allow AI replies. The character's personality and way of speaking come from what you wrote in the character's settings; the game cannot swap the prompt or the model. Signed-in players use their own AI allowance; guests are charged to the author, with a daily ceiling.

Everything else

// A game cannot open windows itself. This asks the player first
const { opened } = await Larch.openUrl('https://example.com');

// Events
Larch.on('pause', () => {});            // Larch covers the game (cards are playing, a line is shown)
Larch.on('resume', () => {});           // back in the game
Larch.on('volume', ({ sound }) => {});  // the player moved the volume, 0 to 1
Larch.on('variables', (all) => {});     // the latest variables when playCard returns
Larch.off('pause', handler);

A game's own window.open calls and links that open a new tab are turned into the same question.

Storage

  • localStorage works. It is kept in the player's browser, one store per build, up to a million characters.
  • IndexedDB does not. Unity's PlayerPrefs depend on it, so PlayerPrefs are gone when the page closes.
  • Write progress that has to last into Larch variables.

Unity (C#)

Download the Unity package (there is a button in the card's Game API section) and put Larch.cs and Larch.jslib anywhere under Assets. No object has to be placed in a scene.

using UnityEngine;

public class Door : MonoBehaviour
{
    void OnMouseDown()
    {
        // Play dialogue over the game, then come back
        Larch.PlayCard(Larch.Param("dialogueCard"), () => Debug.Log("back in the game"));
    }

    public void Win(int score)
    {
        Larch.SetVariable("score", score);
        Larch.GiveItem(Larch.Param("rewardItem"));
        Larch.Complete("win");
    }
}

Every method:

bool   Larch.Embedded                 // whether this build runs inside a Larch web game card
string Larch.Param(name, fallback)    // the card's parameters
Larch.GetInfo(info => { })            // cardId, projectId, locale, playerName

Larch.PlayCard(cardId, onDone)
Larch.GoToCard(cardId)
Larch.Complete()                      // or Larch.Complete("win")

Larch.SetVariable(name, value)        // string, double, bool
Larch.GetVariable(name, value => { }) // value.kind, value.text, value.number, value.flag
Larch.GetString(name, text => { })
Larch.GetNumber(name, number => { })
Larch.GetBool(name, flag => { })

Larch.GiveItem(itemId, count, onDone)
Larch.TakeItem(itemId, count, onDone)
Larch.GetItems(items => { })          // LarchItem[]: id, name, description, iconUrl, count
Larch.GetItemCount(itemId, count => { })

Larch.Say(text, character, emotion, onDone)
Larch.ShowPortrait(character, emotion, position)
Larch.HidePortrait(character)

Larch.GetCard(cardId, card => { })    // LarchCard: lines, choices, nextCardId
Larch.GetCards(cards => { })
Larch.GetCharacters(characters => { })

Larch.AiChat(character, message, reply => { }, error => { })   // reply.reply, reply.emotion
Larch.OpenUrl(url)

Larch.Paused  += () => { };
Larch.Resumed += () => { };
Larch.VolumeChanged += volume => { };
Larch.AutoPause = true;               // set Time.timeScale to 0 and pause sound while Larch covers the game

Testing in the Unity Editor

The Editor has no Larch player:

  • Variables and items live in memory, so you can run your flow to the end.
  • PlayCard and Say write the lines to the Console.
  • GoToCard and Complete log one line.
  • To read the real cards, characters and AI replies, call Larch.Configure once:
#if UNITY_EDITOR
Larch.Configure("PROJECT_ID", "lpk_your_project_api_key");
Larch.SetEditorParam("dialogueCard", "CARD_ID");
#endif

The project API Key is under AI Assist → Project API Key in your account settings. It can only read that one project. Keep it inside #if UNITY_EDITOR so it does not ship with the build: a game played on Larch has no use for it.

Never put an Agent Key (it starts with larch_) in a game. It can edit every project in your account. Larch refuses a game build that carries one.

HTTP API (outside Larch)

Addresses start with https://larch.ink/api/public/v1/projects/<project id>. Every request carries the header X-Larch-Live-Key: <project API Key>.

  • GET /cards: each card's id, title, type, boardId and nextCardId.
  • GET /cards/<card id>: one card's lines and choices. Add ?locale=en for that language's translation.
  • GET /characters: characters and their expression portraits.
  • GET /items: the item library.
  • POST /characters/<character id or name>/chat: an AI reply. The body is { "message": "…" } or { "messages": [...] }; the answer is { reply, emotion, expression }. The project owner's allowance pays.
  • POST /story: walk the story card by card along its links. The body is { "cursor": a card id or null, "advance": true, "choiceIndex": 0 }.
curl https://larch.ink/api/public/v1/projects/PROJECT_ID/cards/CARD_ID \
  -H "X-Larch-Live-Key: lpk_..."

If the project API Key leaks, press Rotate under AI Assist → Project API Key; the old one stops working at once.

Error codes

  • not-allowed: the card does not allow this feature.
  • card-not-found: there is no such card. playCard needs a card on the same whiteboard.
  • item-not-found: the item library has no such item.
  • character-not-found: there is no such character, or it has no portrait.
  • busy: the previous playCard or aiChat has not finished.
  • bad-arguments: an argument has the wrong form. The bag variable cannot be changed with setVariable.
  • rate-limited: too many calls (over 60 a second).
  • unknown-method: there is no such method.
  • not-embedded: this is not running on Larch.
  • network: the server cannot be reached.

When aiChat fails, the message may be the server's own explanation, for example that the allowance has run out.

Current limits

  • In a work exported to a single HTML file, an EXE or an app, web game cards step aside. They need the game files online.
  • Builds that need threads (SharedArrayBuffer) do not run. Export Godot 4 games single-threaded.
  • A game cannot use the camera, the microphone or the location.
  • A save made while playCard is playing loads back on that card, not in the game.

Asking your AI agent to upload it

You can tell your own AI agent (Claude Code, Codex and so on) to upload the game, put it on a card and link it up.

  1. In your account settings, under AI Assist, create an Agent Key and give your agent the full Larch Skill.
  2. In the web game card's Game API section, press Copy AI prompt and paste it to the agent.
  3. Tell it which folder the build is in.

The agent uses these tools (over MCP or REST):

  • larch_web_game_spec: read the spec.
  • larch_web_game_upload, larch_web_game_job: upload the zip in pieces and wait for it to be ready.
  • larch_web_game_html: turn one HTML document into a build.
  • larch_web_game: create or change the card, set parameters and exits, link it. It adds the Web Game extension to the project by itself.
  • larch_web_game_list: list the builds you have uploaded.