> For the complete documentation index, see [llms.txt](https://docs.yarnspinner.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.yarnspinner.dev/3.1/write-yarn-scripts/scripting-fundamentals/line-groups.md).

# Line Groups

To give your dialogue more life and variety, you can also provide lines in a **line group**. When lines are in a line group, Yarn Spinner will choose one of them for you.

Line groups are collections of lines that begin with a `=>` symbol:

{% code overflow="wrap" lineNumbers="true" %}

```markup
title: Start
---
Captain: Navigator, fire the glitter torpedoes! That'll confuse the enemy ships!
=> Navigator: *sighs deeply* Sir, we don't have 'glitter torpedoes.' Those were in your dream last night.
=> Navigator: *eyes roll skyward* Captain, weaponizing craft supplies is not part of standard space combat protocol.
=> Navigator: *Slumps shoulders in defeat* I'll... make a note in the log that you suggested tactical glitter, sir.
===
```

{% endcode %}

In this example, the Captain will say "`Navigator, fire the glitter torpedoes! That'll confuse the enemy ships!`", and then Yarn Spinner will choose one of the subsequent lines to respond with.

{% hint style="info" %}
Line groups are great for running ‘barks’ - collections of short lines that need to run in response to an in-game event. It can be useful to think of them like Yarn Spinner’s existing options `->` syntax, but instead of the player choosing which content to run, the computer picks it for you:

```
=> Guard: Halt!
=> Guard: No entry!
=> Guard: Stop!
```

{% endhint %}

You can attach conditions to lines in a line group, to ensure that they only run when it’s appropriate to do so. Conditions can be any true or false expression, and can also be combined with the `once` keyword to ensure that a line can only run once:

<pre class="language-html" data-overflow="wrap"><code class="lang-html">=> Guard: Greetings, citizen.
<strong>=> Guard: Hello, traveller.
</strong>	Guard: Stay vigilant. // runs after 'Hello, traveller.'
=> Guard: Hail, adventurer! &#x3C;&#x3C;if $player_is_adventurer>>
=> Guard: I used to be an adventurer like you, but then I took an arrow in the knee. &#x3C;&#x3C;once if $player_is_adventurer>>
</code></pre>

{% @yarnspinner/tryyarnspinner id="<https://try.yarnspinner.dev/embed?gist=2deb278dae6a6f679b3d7eae1e9b41fd>" %}

A line in a line group can also have additional lines belonging to it, which will run if the item is selected.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.yarnspinner.dev/3.1/write-yarn-scripts/scripting-fundamentals/line-groups.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
