home/ atoms/ sc-variables-local-global-env

SuperCollider distinguishes local variables (var), single-letter globals (a-z), and environment variables (~name)

SC has three variable scopes. Local variables are declared with var name; inside a code block — they exist only during that evaluation and must be declared and used within the same execution context. Single lowercase letters (a through z) are built-in globals that persist between evaluations; s is conventionally reserved for the local server. Environment variables, prefixed with ~, are also persistent globals but can have arbitrary names longer than one character (~buffer, ~synth). Technically these are slots in the current Environment object, but beginners can treat them as simply persistent named slots. All variable names must begin with a lowercase letter.

Examples

var num; num = 3.cubed; num; — local, only valid inside this block. x = 42; — single-letter global. ~myFreq = 440; — environment variable, persists after evaluation.

Assessment

Which of these three scopes should you use to hold a running Synth that you want to free from a later code block? Why would a local variable fail for this purpose?

“Lowercase a through z are reserved for use as global variables, or you can precede a local variable name with a tilde in order to turn it into a global variable.”
corpus · supercollider-tutorials-full-transcripts-and-code-eli-fields · chunk 3