39. Processing and a frame-based countdown
var countdown: float = 0.0
var timer_running: bool = falsefunc run() -> void:
countdown = 10.0
timer_running = truefunc _process(delta: float) -> void:
if not timer_running:
return
countdown = maxf(0.0, countdown - delta)
if countdown <= 0.0:
timer_running = false
Log("Countdown finished.")Keep the instance alive. delta is elapsed seconds for this frame, so the countdown follows time rather than frame count. Use _physics_process for fixed-step physics work, not simply because a script changes a number.
A process callback should return quickly. Do not start an awaited long routine every frame; it can create many overlapping routines. Set a state flag before starting a job, or use a dedicated Timer/signal.
PCA can pause/suspend preview workspaces and runtime processing. Time scale and pause settings matter. A global checkbox keeps the instance; it does not force every callback to run while its tree/parent is disabled.
