[chuck-users] Global Variables (herman asked)

Perry Cook prc at cs.princeton.edu
Thu Feb 27 12:57:15 EST 2020

You script got scrubbed for some reason, but I suspect that you’re shadowing
the global somehow locally (if you use the same name as an argument or a 
local within a function, it masks the global version).  

Here’s a simple example of using a global:

1000 => float freqGlob; // global frequency variable

SinOsc s => dac;  // note that this osc is treated globally as well

spork ~ sweep(); 

while (true)  {  // main loop randomly (re)sets freq
    Std.rand2f(500.0,3000.0) => freqGlob => s.freq;
    Std.rand2f(0.3,1.0)::second => now;

// this shred sweeps the frequency exponentially down
fun void sweep()  {  
  while (true)  {
    (0.999*=> freqGlob) => s.freq;
    ms => now;

More information about the chuck-users mailing list