Watch Section (Listener) (Section) — skLambda
Addon: skLambda · Category: Section · Since: 1.3.0
Syntax
watch %object% [(with|for) %-objects%] every %timespan% [(within|timeout after) %-timespan%]Description
Polls a value on a timer and runs `on change:` whenever it differs from the last poll (change detection built in). `watch %value% every %timespan%:` re-evaluates the expression each interval. `watch %lambda% for %arguments% every %timespan%:` calls the lambda with those arguments each interval. Inside `on change:`, `old value` and `new value` hold the previous and current values. 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:` (runs whenever the watcher stops, for teardown). The result is a normal listener handle: `pause`, `resume`, `unregister`, `is registered`, and `/sklambda listeners` all work. Declare one with `set %~object% to a watcher on ...` then `register` it, or use the bare `watch ...` form to start immediately. The value is read on the main thread, so the watched expression/lambda must be safe there (the usual Skript rule).
Examples
set {_p} to sender
watch (balance of {_p}) every 2 seconds within 5 minutes:
on change:
send "balance: %old value% -> %new value%" to {_p}
on timeout:
send "stopped watching your balance" to {_p}