home/ atoms/ hydra-thunk-for-live-values

In Hydra, live/reactive values must be wrapped in a thunk `() => …` — bare values are baked at eval time

When a Hydra chain is evaluated, a bare numeric value is captured at that instant and never updated again. To use a value that changes over time — time, mouse, audio FFT bins, or any dynamic source — it must be wrapped in a thunk (a zero-argument arrow function): () => a.fft[2]. Without the thunk the expression reads the value once at eval time (often 0) and stays frozen. When something should animate or react but doesn’t, this is the first thing to check.

Examples

osc(10).rotate(a.fft[2]) // frozen at eval-time value (usually 0) osc(10).rotate(() => a.fft[2]) // live, updates each frame

Assessment

Explain why noise(4).scale(a.fft[0]) does not respond to music even when music is playing, and rewrite it to be reactive.

“bare value is baked in at eval time; only a **thunk** `() => …` is re-read each frame. - `osc(10).rotate(a.fft[2])` → rotates by whatever `a.fft[2]` was **at eval** (usually 0). Frozen.”
context/ · L1-instruments/hydra/gotchas.md · chunk 1