Nearest Within Steps
Returns the closest agent of a selected breed in a given radius.

Description
The Nearest Within Steps block returns the closest agent of a selected breed within a given radius. This is a code block part of the Detection drawer.
Usage
Nearest Within Steps is used to refer to the nearest agent of a selected breed that exists within a given step limit in Spaceland.
Syntax
Inputs in this block:
- A breed from the dropdown menu
- A number (radius in steps)
.webp)
Example
This is a model of a grazing herd of elephants. Because the elephants want to acquire the most food possible, they walk toward the grass that is closest to them within their sensing radius (30 steps).

Notes
This block returns a reference to a single agent, which can be used with other blocks that require agent references.
Related Blocks
- Nearest Within Steps With = - Finds nearest agent with additional trait filtering