Ambient Barks
Ambient barks are the short lines characters call out on their own when something happens nearby. One line plays at a time, then the character stays quiet for a while. A dice roll decides whether they speak, a failed roll waits before the next try, and recent lines are not repeated.

Paste this to your AI
Copy it into Claude, Cursor or ChatGPT. It already has good values and the usual mistakes in it.
Add "Ambient Barks" to my game.
What it should do: Barks make a world feel lived in. Characters comment on what happens around them, and the player hears something alive between the big story moments, without the same few lines becoming a nuisance.
Build it exactly as this state machine. First check that it fits my game, then build it like this:
```mermaid
stateDiagram-v2
[*] --> ready
ready: Ready to talk
speaking: Speaking
cooldown: Staying quiet
ready --> ready: no event or no lines
ready --> speaking: event and roll pass
ready --> cooldown: roll fails
speaking --> speaking: line goes on
speaking --> cooldown: line ends
cooldown --> cooldown: silence goes on
cooldown --> ready: silence is over
cooldown --> speaking: silence ends, line plays
```
Use these starting values:
- lineDuration: 2.5 s
- cooldown: 8 s
- retryDelay: 3 s
- talkChance: 0.5
- memory: 3 lines
Watch out for these common mistakes:
- The crowd talks over each other: Tell your AI: let the characters in one scene share a single speaker slot, so only one line plays at a time and the others stay quiet.
- An event fires every frame: Tell your AI: after a failed roll, wait a few seconds before rolling again.
- Lines queue up and play late: Tell your AI: drop events that arrive while a line is playing instead of queuing them.
- The same line again and again: Tell your AI: remember the last few lines, leave them out of the choice, and never say the line just said again unless it is the only one.
- Lines of one event block lines of another: Tell your AI: give every line its own id, and remember ids, not positions.
Do not change anything else in the game. Do not claim anything without proof: model what it takes, and show me what your solution rests on and how I can see that it works. If you cannot show something, say you do not know. When you are done, tell me in plain words how to try it.Or skip this and connect the MCP: your AI then finds all of this by itself.Connect the MCP
What it does
Barks make a world feel lived in. Characters comment on what happens around them, and the player hears something alive between the big story moments, without the same few lines becoming a nuisance.
How it runs, as a diagram
Everything it can be in, and what moves it on. Your AI builds from exactly this.
How it runs, as a diagram
- Ready to talk → Ready to talk: no event or no lines
- Ready to talk → Speaking: event and roll pass
- Ready to talk → Staying quiet: roll fails
- Speaking → Speaking: line goes on
- Speaking → Staying quiet: line ends
- Staying quiet → Staying quiet: silence goes on
- Staying quiet → Ready to talk: silence is over
- Staying quiet → Speaking: silence ends, line plays
Good starting values
| Value | Start with | What it changes |
|---|---|---|
| lineDuration | 2.5 s | How long a line is on screen or in the air. Long enough to read, short enough that it does not block the next thing. |
| cooldown | 8 s | The silence after a line ends, before the character may speak again. This is the main dial for how chatty the world feels. |
| retryDelay | 3 s | The wait after a failed roll before the next roll. Without it, an event that fires every frame is rolled sixty times a second and nearly always passes. |
| talkChance | 0.5 | The chance, from 0 to 1, that an event leads to a line. At 1 every event is answered. It is never zero, because then the character would never speak. |
| memory | 3 lines | How many of the latest lines are not repeated while something else can be said. Zero allows repeats at any time. |
What usually goes wrong
The crowd talks over each other
Ten guards all react to the same noise in the same moment, and the player hears ten lines at once, none of them understood.
Fix: Tell your AI: let the characters in one scene share a single speaker slot, so only one line plays at a time and the others stay quiet.
An event fires every frame
"The player is near" is true for sixty frames a second. A chance of one in two is rolled over and over, so the character speaks almost at once, every time.
Fix: Tell your AI: after a failed roll, wait a few seconds before rolling again.
Lines queue up and play late
Events that arrive during a line are stored and played afterwards. The guard shouts about a thief the player left behind half a minute ago.
Fix: Tell your AI: drop events that arrive while a line is playing instead of queuing them.
The same line again and again
Choosing at random lets the same line come up twice in a row, which sounds broken. With a small pool it happens often.
Fix: Tell your AI: remember the last few lines, leave them out of the choice, and never say the line just said again unless it is the only one.
Lines of one event block lines of another
The memory counts positions in a pool, so a line from the rain pool blocks an unrelated line at the same position in the door pool.
Fix: Tell your AI: give every line its own id, and remember ids, not positions.
How to check it works
- A character who is quiet and ready, and a pool of five lines. an event arrives and the roll passes: one line from the pool starts, it runs for the full line time, and the character counts as speaking.
- A ready character and an event that arrives every frame. the first roll fails: nothing is said, a wait of a few seconds starts, no new roll is made during it even if the next roll would pass, and a roll after it can pass.
- A line is being said. another event arrives: the line goes on unchanged and the new event is dropped, not queued.
- A line has just ended. events arrive during the silence and then after it: nothing is said during the silence, and a line can start once it is over.
- A pool of five lines, a memory of three, and the same pick every time. five lines are said one after another: the first four are all different, and the fifth is the first line that has dropped out of memory.
- A pool of two lines and a memory longer than the pool. six lines are said one after another: they alternate and the same line never comes twice in a row.
- A pool with a single line. it is needed several times: that line is said each time, because there is nothing else.
- An event with no lines to offer. it arrives: nothing is said, no wait starts, and the character stays ready.
- A chance of one half. the roll is 0, the roll is exactly the chance, and the pick is 1, almost 1, or below 0: a roll of 0 passes, a roll equal to the chance fails, a pick at or near 1 gives the last line, and a pick below 0 gives the first.
- A ready character. the roll is not a number, or the pick is not a number: a bad roll says nothing and starts no wait, and a bad pick counts as the first option.
- A line from one pool was just said. the next event offers a different pool that contains the same line: that line is left out, because lines are remembered by id and not by position.
- A memory of zero. a line is said: no lines are remembered.
Works well with
- Dialogue System: A bark is a line nobody asked for, so it should never cut in on a real conversation. Let a conversation take over: stop barks for that character while the conversation runs.
- Relationship Meters: A friendly character greets, an unfriendly one grumbles, and the same event gives a different bark. Choose the pool from the character's level, then pick the line.
- World State Flags: After the bridge falls, the guards can stop talking about it. The pool changes with the world. Ask the flags when you build the pool, not when you say the line.
Common questions
what are barks in games
Short lines a character calls out on their own when something happens near them, like warning of rain or commenting on the player. They fill the quiet between story scenes and make the world feel awake.
how do i stop npcs repeating themselves
Keep a short memory of the last few lines and leave them out of the choice, and give every line an id so the memory works across different events. Write enough lines, at least five per event.
what do i tell my ai to add barks
Paste this: Add ambient barks. A character says one line at a time, then stays silent for 8 seconds. A bark has a 50 percent chance, and after a failed roll waits 3 seconds. Drop events that arrive during a line, and never repeat any of the last 3 lines.
how often should characters bark
Start with a silence of about eight seconds after each line and a chance of one half. If players mention that it is too much, lengthen the silence first, and lower the chance second.
Where it comes from
We could not find a reliable origin for this one yet.
What was checked
- 14 tests pass on the reference code.
- The state diagram was checked against the code, at the default values and at every listed low and high value.
Your AI gets the code
Tested example code comes through the Spielerando connection, so your AI can use it right away. How to connect it