Implementation:AIScientists Dev WorldSeed for each ops
| Knowledge Sources | |
|---|---|
| Domains | DSL, Simulation |
| Last Updated | 2026-10-26 18:00 GMT |
Overview
Concrete DSL effect operator that iterates entities matching criteria and applies sub-effects to each, provided by the WorldSeed library.
Description
The for_each effect operator registers itself via `register_effect("for_each", _exec_for_each)`. It queries entities by type from the state store, applies optional match filters (property checks beyond type) and a `where` clause, then executes a list of sub-effects against each matching entity. Inside sub-effects, `$entity` resolves to the current entity's ID, enabling batch mutations like resetting all un-folded agents' `acted` flag.
Usage
Use this operator in scene YAML when you need to apply the same set of effects to every entity matching a type and filter — e.g., resetting per-tick flags, broadcasting state changes, or iterating over a collection of game objects.
Code Reference
Source Location
- Repository: WorldSeed
- File: src/worldseed/dsl/effects/for_each_ops.py
Signature
def _exec_for_each(
effect: EffectConfig,
store: StateStore,
event_log: EventLog,
ctx: dict[str, Any],
tick: int,
) -> None:
"""Iterate entities matching criteria and apply sub-effects to each."""
Import
# Auto-registered on import of the effects package:
# import worldseed.dsl.effects # registers "for_each" operator
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| effect.match | dict | Yes | Filter with `type` key (required) + optional property checks |
| effect.where | str | No | WHERE clause for additional filtering |
| effect.sub_effects | list[EffectConfig] | Yes | Effects to apply to each matching entity |
Outputs
| Name | Type | Description |
|---|---|---|
| side effect | None | Mutates state store via sub-effects |
Usage Examples
# YAML scene config — reset all un-acted agents
- operator: for_each
match: { type: agent }
where: "folded == false"
effects:
- { operator: set, target: "$entity.acted", value: false }