# `tecs.ecs.runif` Provides timer, state and logical predicates for system dispatch. ## Functions ### `after` _function_ ```nupp function after(delay: number): world.RunIf ``` Allows one dispatch after a delay and removes the system before its body runs. #### Arguments | Name | Type | Description | | --- | --- | --- | | `delay` | `number` | The non-negative finite delay in seconds; zero fires on the first call. | #### Returns | Type | Description | | --- | --- | | `world.RunIf` | Returns a new stateful system predicate. | #### Raises - Raises when delay is negative or non-finite. ### `both` _function_ ```nupp function both(lhs: world.RunIf, rhs: world.RunIf): world.RunIf ``` Allows dispatch only when both predicates allow it, evaluating left first. #### Arguments | Name | Type | Description | | --- | --- | --- | | `lhs` | `world.RunIf` | The predicate that always receives the dispatch delta. | | `rhs` | `world.RunIf` | The predicate evaluated only when lhs returns true. | #### Returns | Type | Description | | --- | --- | | `world.RunIf` | Returns a short-circuiting conjunction. | ### `cooldown` _function_ ```nupp function cooldown(duration: number): world.RunIf ``` Allows the first dispatch immediately, then waits a cooldown between runs. #### Arguments | Name | Type | Description | | --- | --- | --- | | `duration` | `number` | The non-negative finite cooldown in seconds; zero always allows a run. | #### Returns | Type | Description | | --- | --- | | `world.RunIf` | Returns a new timer that discards elapsed overshoot after each run. | #### Raises - Raises when duration is negative or non-finite. ### `either` _function_ ```nupp function either(lhs: world.RunIf, rhs: world.RunIf): world.RunIf ``` Allows dispatch when either predicate allows it, evaluating left first. #### Arguments | Name | Type | Description | | --- | --- | --- | | `lhs` | `world.RunIf` | The predicate that always receives the dispatch delta. | | `rhs` | `world.RunIf` | The predicate evaluated only when lhs returns false. | #### Returns | Type | Description | | --- | --- | | `world.RunIf` | Returns a short-circuiting disjunction. | ### `every` _function_ ```nupp function every(interval: number, jitter: number?, generator: random.Random?): world.RunIf ``` Allows repeated dispatches separated by an interval, retaining elapsed overshoot. #### Arguments | Name | Type | Description | | --- | --- | --- | | `interval` | `number` | The positive finite base interval in seconds. | | `jitter` | `number?` | The non-negative finite variance in seconds, defaulting to zero. | | `generator` | `random.Random?` | The caller-owned random generator, required for nonzero jitter. | #### Returns | Type | Description | | --- | --- | | `world.RunIf` | Returns a new timer, firing at most once per call. The first interval is unjittered; later intervals clamp to at least one percent of the base interval. | #### Raises - Raises for invalid durations or nonzero jitter without a generator. ### `inState` _function_ ```nupp function inState(name: string): world.RunIf ``` Allows dispatch only while the named state is on top of the world stack. #### Arguments | Name | Type | Description | | --- | --- | --- | | `name` | `string` | The state name to match; it need not be registered yet. | #### Returns | Type | Description | | --- | --- | | `world.RunIf` | Returns a predicate that reads the current state on each call. | ### `negate` _function_ ```nupp function negate(predicate: world.RunIf): world.RunIf ``` Inverts whether a predicate allows dispatch. #### Arguments | Name | Type | Description | | --- | --- | --- | | `predicate` | `world.RunIf` | The predicate to evaluate once per call. | #### Returns | Type | Description | | --- | --- | | `world.RunIf` | Returns its logical negation, preserving its timer and other side effects. |