# Node Groups

In Yarn Spinner, you can also create node groups. A **node group** is collection of nodes that share the same name that Yarn Spinner will choose from.

To create a node group, you create multiple nodes that all share the same name, and ensure that each of the nodes have at least one `when:` header.

The `when:`header tells Yarn Spinner about the conditions that must be met in order to run the node:

<pre class="language-html"><code class="lang-html">title: Guard
<a data-footnote-ref href="#user-content-fn-1">when: once</a>
---
Guard: You there, traveller!
Player: Who, me?
Guard: Yes! Stay off the roads after dark!
===
title: Guard
<a data-footnote-ref href="#user-content-fn-2">when: always</a>
---
Guard: I hear the king has a new advisor.
===
title: Guard
<a data-footnote-ref href="#user-content-fn-3">when: $has_sword</a>
---
Guard: No weapons allowed in the city!
===

</code></pre>

Node groups are combined into a single node that performs the appropriate checks and then runs one of the node group’s members. You start dialogue with a node group using its name. You can also use the `jump` or `detour` statements to run a node group from somewhere else in your Yarn scripts.

Node groups will be visualised in a box of their own in the Graph View of Yarn Spinner for Visual Studio Code:

<figure><img src="/files/inGzf0KbNe5h0raTLXdC" alt=""><figcaption><p>Node groups are shown in the Graph View.</p></figcaption></figure>

{% hint style="info" %}
Node groups are similar to [line groups](/write-yarn-scripts/scripting-fundamentals/line-groups.md) in their behaviour, but give you more room to create longer passages of content. Your C# code can also check to see how many (if any) nodes can run, which is covered in the Saliency section.
{% endhint %}

You can add as many `when:` headers to a node as you want.

[^1]: this version of the node can only run once

[^2]: this version is the line can run any time

[^3]: this version of the node can only run if the variable `$has_sword` is true


---

# Agent Instructions: 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:

```
GET https://docs.yarnspinner.dev/write-yarn-scripts/advanced-scripting/node-groups.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
