home/ atoms/ hydra-reactive-thunk

A reactive Hydra parameter must be written as a () => … thunk — a bare expression is evaluated once at eval time and frozen

In Hydra, parameter values that should change over time (including a.fft reads) must be wrapped in a () => arrow function called a thunk. Hydra evaluates thunks every frame. A bare expression — even one referencing a.fft[0] — is evaluated exactly once when the sketch is eval()-ed and its result is stored as a constant. The pattern () => 0.6 + a.fft[0] * 2.5 is reactive; 0.6 + a.fft[0] * 2.5 is frozen at the value of a.fft[0] at boot time. This is the single most common ‘why isn’t it reacting?’ bug.

Examples

osc(10,0.1,()=>0.6+a.fft[0]*2.5) — brightness updates every frame ✅. osc(10,0.1, 0.6+a.fft[0]*2.5) — brightness is the value of a.fft[0] at the moment of eval, then frozen ❌.

Assessment

A student writes osc(20,0.1,1+a.fft[0]).out(). The sketch compiles without error but the oscillator brightness never changes. Identify the bug, explain why it occurs, and write the corrected line.

“A value that should track the audio must be written as a **`() => …` thunk**, evaluated by Hydra every frame. A bare expression (`a.fft[0] * 2.5`) is evaluated **once** at `eval()` time and frozen.”
context/ · L2b-av-link/feature-contract.md · chunk 1