Builtin Library
README.md
probe.onChange
Fire when a value becomes different from what it was.
Reads the expression once per frame and fires on the transition, so it reaches anything the engine will evaluate — a component field, a light's intensity, a transform's position, a table lookup — without that value needing to publish an event of its own.
probe.onChange("entity.find('Lamp').component.get('Light').intensity", {
notice = "the lamp got bright",
when = "value >= 5",
run = "return value",
})
The context carries value and previous, so a probe can report the step as
well as the destination.
Pair it with when to name the value you are waiting for rather than every
change on the way there: the example fires the first time intensity reaches
five, not on each increment toward it.
It samples once per frame. A value that changes and changes back inside
one frame reads as no change at all, and one held for a frame or two is an
edge it may catch going up and miss coming down. When what you are chasing is
that short-lived, probe the CODE that sets it with onLine instead: a line
fires every time it runs, whatever the frame rate.
The value at arm time is the baseline, not a hit — a probe that fired on arming would report the state you already knew. An expression that cannot be evaluated yet (an entity not spawned, a component not added) is not a change; it becomes one when it starts answering.