Skip to content

A language for interactive stories

Once upon a script.

Write it like a screenplay, run it like a game. Bruja is dialogue and choices as syntax, plus a small, Lua-style language for everything else. For RPGs, adventure games, visual novels, interactive fiction, mods and game logic.

dotnet tool install -g Bruja.Cli · Unity package · VS Code · Source

main.bruja
// This story is running in your browser, right now.
gold = 12
-> the_gate

# The Gate
> @Guard: [Halt! Who goes there?|Still here?|You again.]
    * Show your pass
        > @Guard: That's a napkin.
    * if gold >= 5: Offer a bribe
        gold -= 5
        > @Guard: I saw nothing.
        -> city
    + Roll for it
        roll = 2d6
        if roll >= 8:
            > You roll {roll}. He sneezes; you slip past.
            -> city
        > You roll {roll}. He grabs your collar.
-> the_gate

# City
> The city opens up, loud and bright.
> You have {gold} [count gold: gold coins | gold coin | gold coins] left.
-> end

Waking the storyteller…

Press 1–3 to choose

That's a real story, compiled and running in your browser. Pick a choice and watch which line of the script ran.

Two languages' worth, in one.

Writers get Ink's screenplay feel. Programmers get closures, generators and events. It's the same file.

Choices that remember

* choices disappear once picked, + choices stay, and {conditions} show a choice only when it makes sense.

-> tavern

# Tavern
> @Barkeep: What'll it be?
    * Ask about the old map
        > @Barkeep: Gone. Sold it last winter.
    * if visits("tavern") > 1: Ask again, louder
        > @Barkeep: Still gone.
    + Leave
        -> street
-> tavern

# Street
> The door swings shut behind you.
-> end

Text that changes

Sequences, cycles, random picks, plurals and lists, right inside a line.

bag = ["a rope", "a lamp", "three apples"]
for day in 1..3:
    > [Morning.|Another morning.|The last morning.] You carry [and: bag].
    bag.pop()
> You have [count len(bag): nothing | one thing | {len(bag)} things] left.

Speakers, markup and tags

@Name (mood): says who is talking, <i>markup</i> styles the text, and #tags ride along for the game.

> @Mira (worried): Did you hear <i>that</i>?<pause=0.6> #sfx:thunder
    * Hold the lantern up #icon:lantern
        > @Ash: Just the storm.
    * Say nothing
        > @Mira: ...right.

Same scene, six ways.

A merchant, a purchase you can make once, a dice roll to haggle, a way out. Compare for yourself.

Bruja13 lines
# Market
> @Merchant: Fine blades, cheap!
    * if gold >= 10: Buy a sword
        gold -= 10
        > @Merchant: A fine choice.
    + Haggle
        if 2d6 >= 9:
            > He sighs and says the price is still ten, but he says it nicely.
        else:
            > He laughs at you.
    + Leave
        -> square
-> market
Ink15 lines
=== market ===
Merchant: Fine blades, cheap!
* if gold >= 10: [Buy a sword]
    ~ gold -= 10
    Merchant: A fine choice.
+ [Haggle]
    ~ temp roll = RANDOM(1, 6) + RANDOM(1, 6)
    {roll >= 9:
        He sighs and says the price is still ten, but he says it nicely.
    - else:
        He laughs at you.
    }
+ [Leave]
    -> square
- -> market

Made to live inside a game.

A small .NET runtime with no dependencies, MIT-licensed, tested on Mono and free of reflection for IL2CPP. A Unity package is included.

The game asks for the next line

Like Ink, your game pulls one line at a time, so it owns the UI, timing and voice.

story.Start(program);
while (story.CanContinue) {
    string line = story.Continue();
    var choices = story.CurrentChoices;
}

Tags and game functions

#tags ride along with lines. extern declares functions the game provides.

extern giveItem
> @Keeper: Take this. #vo:keeper_04
giveItem("lantern")

Pause for the game

wait hands control back for an animation, a fight, a cutscene.

> The bridge collapses.
wait "cutscene_bridge"
> You wake on the riverbank.

Save anything

One call saves the whole story: variables, visits, even a paused generator.

byte[] save = story.SaveState();
// …later
story.LoadState(save);
  • Errors before it runs. Every problem with its line and column: typos, missing threads, misspelled speakers.
  • Repeatable randomness. Seed the dice and every playthrough replays exactly, on every platform.
  • Ship the compiler too. The compiler is MIT too, so players can write mods that compile in your game.

Ship it in every language, and every voice.

Every line gets a stable ID. Translators get a table, actors get their own script, the game switches language at runtime, and the script never changes. Pick a language:

Waking the storyteller…

fr.csv
@speaker.GuardGarde
g01Halte ! Qui va là ?
g02Ah, {0}. Vous avez {1}.
g02.1aucune pièce
g02.2une pièce
g02.3{0} pièces
g03Payer le péage
g04<b>Merci.</b> Circulez.
g05Passer sans payer
g06{0}
g06.1Hé !
g06.2J'ai dit hé !
g07La porte se referme derrière vous.
  • IDs that survive rewrites. #line:g01 stays put when a line is reworded or moved, so translations and recordings stay attached.
  • A table translators know. CSV with the speaker, mood, notes from the script, and what each {0} stands for. Translate it in the web IDE, next to the story's text, or in any spreadsheet. Character names are translated once.
  • Keeps up with the writers. New lines, lines edited since they were translated, and deleted ones are marked in the table, and bruja lines sync brings every language up to date.
  • Checked before it ships. bruja lines check catches broken placeholders and markup, and fails the build.
  • Voice-over ready. The current line's ID is a file name: vo/fr/g01.ogg. Each actor gets a script with only their lines, the mood and the line before, to mark recorded right in the web IDE (lines rewritten since are flagged), and the whole story reads as a screenplay with its branches. The localization and voice-over guide

How it compares.

The short version. The full table is on the Why page, along with where the others are stronger.

FeatureBrujaInkYarn SpinnerTwine (Harlowe)Ren'PyChoiceScriptLua
Dialogue and choices are syntaxYesYesYesChoices (links)YesYesNo
Once-only, sticky and fallback choicesYesYesOnce and stickyBy handPartialPartialNo
Localization by line ID, with CSV toolsYesNoYesNoOwn formatNoNo
Loops, arrays and objectsYesNo (LIST sets)NoYesPythonArrays onlyTables
Functions and closuresYesFunctionsFrom the gameCustom macrosPythonSubroutinesYes
Errors before the story runsYesYesYesWhen playedLintQuicktestSyntax only

Free course · 36 short lessons · no sign-up

The Quest

Ten short chapters, one small mystery. You'll write The Lighthouse from its first line to a finished game you can share, and meet every major feature on the way. Progress saves as you go.

  1. 1First words
  2. 2Crossroads
  3. 3Threads
  4. 4Remembering
  5. 5Living text
  6. 6Logic
  7. 7Building blocks
  8. 8Scenes that pause
  9. 9Talking to the game
  10. 10The full story

Know Lua already? There's an 8-lesson fast lane.

Lesson 1, task 1 Write a line of dialogue. Lines start with >.

Continue in lesson 1 →