Skip to main content

Nearest Within Steps

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

Nearest Within Steps block

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)
Nearest Within Steps syntax

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).

Nearest Within Steps example code

Notes

This block returns a reference to a single agent, which can be used with other blocks that require agent references.