Watch Condition (Listener) (Section) — skLambda
Addon: skLambda · Category: Section · Since: 1.3.0
Syntax
watch (when|whether) <.+>Description
Edge-triggered condition watcher: polls a condition on a timer and fires on the transition, not on every poll. `watch when <condition> every %timespan%:` with `on rising:` (the moment it goes false -> true) and/or `on falling:` (true -> false). This is "do X the moment Y first becomes true" without writing a poll loop. The condition's state at the first poll is the baseline, so a transition is needed to fire (a condition already true at the start won't fire `on rising` until it goes false then true again). Optional entry: `owner: %offlineplayer/entity/chunk/world%` auto-stops the watcher when the owner goes away. Optional blocks: `on timeout:` (needs `within %timespan%`) and `on end:`. The result is a normal listener handle: `pause`, `resume`, `unregister`, `is registered`, and `/sklambda listeners` all work. The condition is checked on the main thread.
Examples
set {_p} to sender
watch when (health of {_p} < 6) every 1 second within 10 minutes:
on rising:
send "<red>low health!" to {_p}
on falling:
send "<green>back to safe health" to {_p}