> For the complete documentation index, see [llms.txt](https://docs.candy-smith.com/main/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.candy-smith.com/main/bubble-shooter-toolkit/scripts/scripts-overview/getneighbours.md).

# GetNeighbours

This method allows you to find and retrieve the neighbors of a particular `Ball` in your game. You can specify both the type of `Ball` you are interested in and a condition to further filter these neighbouring balls.

**Syntax:**

```csharp
var filteredNeighbours = LevelUtils.GetNeighbours<T>(Ball ball, Func<T, bool> filter);
```

**Parameters:**

* `T` : The type of the `Ball` that you want to find among the neighbours. This could be any class that derives from the `Ball` base class (like `ColorBall` for instance).
* `ball` : The `Ball` whose neighbours you want to find.
* `filter` : A `Func<T, bool>` that represents the condition to further filter the neighbours. This is a function that takes a `Ball` of type `T` and returns a boolean. If the function returns `true` for a specific `Ball`, then that `Ball` will be included in the returned array of neighbours.

**Example:**

```csharp
var filteredNeighbours = LevelUtils.GetNeighbours<ColorBall>(someBall, ball => ball.GetColor() == targetColor);
```

In this example, `GetNeighbours` is called to find all neighboring `ColorBall`s of `someBall` that have the same color as `targetColor`. The method returns an array of these `ColorBall`s.

Here, `ball => ball.GetColor() == targetColor` is a lambda expression that represents the `filter` function. It checks if the color of a `ColorBall` is the same as `targetColor`.

This method is powerful because it allows you to customize the condition for filtering neighbours, resulting in more flexibility when designing game mechanics. For example, you could easily find all `ColorBall`s of a certain color, or `BombBall`s that are about to explode, etc.


---

# 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.candy-smith.com/main/bubble-shooter-toolkit/scripts/scripts-overview/getneighbours.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.
