ClosureForGroups

Closures View source
ClosureForGroups

Executes the given closure for every unit in this group, removing the units from the group as processed. Return true to continue iteration, false to stop.

Source on GitHub

📖 Read the detailed guide for hand-written examples and background.

Interfaces

ForGroupCallback

public interface ForGroupCallback

Members:

  • callback(unit u)

ForGroupCallbackUntil

public interface ForGroupCallbackUntil

Return true to continue iteration, false to stop.

Members:

  • callback(unit u) returns bool

ForGroupCallbackD

public interface ForGroupCallbackD

Members:

  • callback(destructable d)

Functions

forUnitsOfType

public function forUnitsOfType(string unitname, ForGroupCallback c)

Executes the given closure for every unit of the given type. Remember that names of custom units are “custom_[typeId]”

forUnitsOfTypeCounted

public function forUnitsOfTypeCounted(string unitname, int count, ForGroupCallback c)

Executes the given closure for every unit of the given player. Cancels itself after count iterations

forUnitsOfPlayer

public function forUnitsOfPlayer(player p, ForGroupCallback c)

Executes the given closure for every unit of the given player

forUnitsAll

public function forUnitsAll(ForGroupCallback c)

Executes the given closure for every existing unit

forUnitsInRect

public function forUnitsInRect(rect r, ForGroupCallback c)

Executes the given closure for every unit in the given rect

forUnitsInRectCounted

public function forUnitsInRectCounted(rect r, int count, ForGroupCallback c)

Executes the given closure for every unit in the given rect. Cancels itself after count iterations

forUnitsInRange

public function forUnitsInRange(vec2 pos, real radius, ForGroupCallback c)

Executes the given closure for every unit in range of the given position

forUnitsInRange

public function forUnitsInRange(vec2 pos, real radius, bool collisionSizeFiltering, ForGroupCallback c)

Executes the given closure for every unit in range of the given position With collisionSizeFiltering true it will take the units’ collision into account.

forUnitsInRangeCounted

public function forUnitsInRangeCounted(vec2 pos, real radius, int count, ForGroupCallback c)

Executes the given closure for every unit in range of the given position Cancels itself after count iterations

forUnitsSelected

public function forUnitsSelected(player p, ForGroupCallback c)

Executes the given closure for every unit selected by the given player

forNearestUnit

public function forNearestUnit(vec2 pos, real range, filterfunc filter, ForGroupCallback c)

Executes the given closure for the closest unit inside the given range of the given position, matching the provided filter. If there is no unit in range, the closure will be run with “null”

forUnitsOfTypeUntil

public function forUnitsOfTypeUntil(string unitname, ForGroupCallbackUntil c)

Executes the given closure for every unit of the given type. Return true to continue iteration, false to stop callback invocation.

forUnitsOfPlayerUntil

public function forUnitsOfPlayerUntil(player p, ForGroupCallbackUntil c)

Executes the given closure for every unit of the given player. Return true to continue iteration, false to stop callback invocation.

forUnitsAllUntil

public function forUnitsAllUntil(ForGroupCallbackUntil c)

Executes the given closure for every existing unit. Return true to continue iteration, false to stop callback invocation.

forUnitsInRectUntil

public function forUnitsInRectUntil(rect r, ForGroupCallbackUntil c)

Executes the given closure for every unit in the given rect. Return true to continue iteration, false to stop callback invocation.

forUnitsInRangeUntil

public function forUnitsInRangeUntil(vec2 pos, real radius, ForGroupCallbackUntil c)

Executes the given closure for every unit in range of the given position. Return true to continue iteration, false to stop callback invocation.

forUnitsSelectedUntil

public function forUnitsSelectedUntil(player p, ForGroupCallbackUntil c)

Executes the given closure for every unit selected by the given player. Return true to continue iteration, false to stop callback invocation.

forDestructablesInRange

public function forDestructablesInRange(vec2 pos, real range, ForGroupCallbackD cb)

Executes the given closure for all destructables in a rect that incompasses the circle with the range radius at the given position.

forDestructablesInRange

public function forDestructablesInRange(vec2 pos, real range, boolexpr filter, ForGroupCallbackD cb)

Executes the given closure for all destructables in a rect that incompasses the circle with the range radius at the given position.

forDestructablesInRect

public function forDestructablesInRect(rect r, ForGroupCallbackD cb)

Executes the given closure for all destructables in the given rect

forDestructablesInRect

public function forDestructablesInRect(rect r, boolexpr filter, ForGroupCallbackD cb)

Executes the given closure for all destructables in the given rect

forNearestDestructable

public function forNearestDestructable(vec2 pos, real range, ForGroupCallbackD c)

Executes the given closure for the closes destructable in the given rect. If there is no destructable in range, the closure will be run with “null”

Extension Functions

group.forEachFrom

public function group.forEachFrom(ForGroupCallback cb)

Executes the given closure for every unit in this group, removing the units from the group as processed

group.forEachIn

public function group.forEachIn(ForGroupCallback cb)

Executes the given closure for every unit in this group, keeping all units in the group

group.forEachFromUntil

public function group.forEachFromUntil(ForGroupCallbackUntil cb)

group.forEachInUntil

public function group.forEachInUntil(ForGroupCallbackUntil cb)

Executes the given closure for every unit in this group, keeping all units in the group. Return true to continue iteration, false to stop.