Nearest Within Steps With =
Returns the closest agent of a selected breed in a given radius with a specific trait.

Description
The Nearest Within Steps With = block returns the closest agent of a selected breed with a specific trait value that exists within a given step limit in Spaceland. This is a code block part of the Detection drawer.
Usage
Nearest Within Steps With = is used to refer to the nearest agent of a selected breed AND trait that exists within a given step limit in Spaceland.
Syntax
Inputs:
- A breed from the first dropdown menu
- A number (radius in steps)
- A trait from the second dropdown menu
- A value to check for

Example
This is a model of a grazing herd of hungry elephants. In this model, there are two species of grass (blue and red). The elephants prefer blue grass but do not mind red grass. Because the elephants want to eat as much blue grass as possible, they walk toward the blue grass that is closest to them within their sensing radius (while eating red grass if they happen across it on the way). Toward the end of the simulation, you can observe that there is plenty of leftover red grass.

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 - Finds nearest agent without trait filtering