# Groups

**Groups** are tags that refer to a set of other tags. The tags within the group could [refer directly to particular stimulus files](/bittsy/creating-protocols/tags/tags-referencing-files.md), or they could be groups themselves.

```
LET <tag> = {<tag1>, <tag2>, <tag3>, ... <tagN>}
```

Tags within a group should be separated by a comma and a space, and there should be no spaces between the opening curly brace and first tag name or the last tag name and the closing curly brace.

Groups refer to tags that have been previously defined, and create a hierarchical structure.

```
LET dog = "C:\BITTSy-Stimuli\animals\dog.png"
LET cat = "C:\BITTSy-Stimuli\animals\cat.png"
LET snake = "C:\BITTSy-Stimuli\animals\snake.png"
LET turtle = "C:\BITTSy-Stimuli\animals\turtle.png"

LET mammals = {dog, cat}
LET reptiles = {snake, turtle}

LET animals = {mammals, reptiles}
```

Below is a visualization of the relationships of tags in the above example.&#x20;

![](/files/-LtfCc0ZmVREdO32xh9W)

In this example, `dog`, `cat`, `snake`, and `turtle` refer directly to files (the tag type covered in the [previous section](/bittsy/creating-protocols/tags/tags-referencing-files.md)). The tags `mammals`, `reptiles`, and `animals` are all groups - but while the members of `mammals` and `reptiles` are tags referring to files, `animals` is a group of other groups.

Groups allow for [random selection](/bittsy/creating-protocols/selection-and-randomization.md) from within a set of tags, which can be used iteratively to select subsets of stimuli before selecting a particular stimulus from the final subset. Ultimately, the purpose will be to present a selected stimulus using an [action statement](/bittsy/creating-protocols/action-statements.md). In order to select through a consistent number of steps, no matter which tags from within groups are chosen, the **tags that are contained in a single group should be at the same level in the tag hierarchy**. For example, if we wanted to make a group that was the set of the above animals that have legs, we could define:

```
LET has_legs = {dog, cat, turtle}
```

But we would NOT use:

```
LET has_legs = {mammals, turtle}
```

because if `mammals` is selected first from the group, there is another layer of selection required before finally presenting the stimulus than if we selected `turtle` initially. BITTSy cannot proceed through different numbers of selection steps based on what is chosen.

{% hint style="info" %}
The above point is especially important in protocols using [loops](/bittsy/creating-protocols/loops.md). But if your selections from your group are not inside a loop, and are occurring in a [fixed order](/bittsy/creating-protocols/selection-and-randomization.md#fixed-order-and-random-order) (such that you *know* when you're selecting another group and when you're selecting a tag) you can construct a group with tags at different levels in the tag hierarchy - there's nothing stopping you. But the fix below *always* works.
{% endhint %}

In cases where you really want something more like `{mammals, turtle}`, you can use "dummy groups," which contain only one item, to get around this issue.

```
LET dog = "C:\BITTSy-Stimuli\animals\dog.png"
LET cat = "C:\BITTSy-Stimuli\animals\cat.png"
LET snake = "C:\BITTSy-Stimuli\animals\snake.png"
LET turtle = "C:\BITTSy-Stimuli\animals\turtle.png"

LET mammals = {dog, cat}
LET testudines = {turtle}

LET has_legs = {mammals, testudines}
```

{% hint style="info" %}
**Note**: You can go back and forth between defining tags that reference files or tags that are groups as you write protocols. However, whenever a group is defined, all of its component tags must have already been defined earlier in the protocol. BITTSy [validates protocols](/bittsy/running-protocols/how-to-run-a-protocol.md#validating-a-protocol) by reading line by line, and if a tag name is referenced inside a group *before* it is defined through a `LET` statement, this will cause a validation error.
{% endhint %}

## Groups of SIDES

There is one special type of group that doesn't contain tags as its elements - it contains side names. This allows for random selection not just of stimulus files (like other groups), but also of presentation location.

```
LET <tag> = {<side1>, <side2>, ... <sideN>}
```

```
LET stim_locations = {LEFT, CENTER, RIGHT}
LET targetsides = {LEFT, RIGHT}
```

The side names that can be used in groups should be previously defined in the [starting SIDES definition](/bittsy/creating-protocols/starting-definitions.md#sides).&#x20;


---

# 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://ldevumd.gitbook.io/bittsy/creating-protocols/tags/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.
