home/ atoms/ p5live-softcompile-scope

P5LIVE softCompile only replaces changed functions, leaving global-variable or setup edits to trigger a full hardCompile

P5LIVE performs two kinds of recompile. A softCompile swaps only the edited function body while keeping sketch state alive — useful for editing code inside draw() without visual interruption. A hardCompile (full sketch restart) is triggered when you edit a global variable, setup(), or preload(). The key gotcha: any live-evolving state that lives in a global (counters, particle arrays) will be reset by a hardCompile. Keep mutable performance state inside draw(), not at the global scope, to avoid unintended resets mid-set. Running an unchanged sketch forces a hardCompile and is the sanctioned way to clear the canvas or reset instances without touching the code.

Examples

Move a particle array from a global let particles = [] into a variable scoped inside draw(), or use a flag to reinitialise only when wanted. Editing a class body leaves old instances on the old code until the next hardCompile or re-emit.

Assessment

Given a sketch whose evolving state lives in a global variable, predict what happens when the performer edits a line of setup(). Then propose a refactor that keeps the state alive across normal edits.

“the whole sketch restarts, the background clears, class instances reset. If your evolving state lives in a global, every keystroke on that line nukes the performance. Keep live-evolving state inside `draw()`.”
context/ · L1-instruments/p5live/gotchas.md · chunk 1