20.do{} vs. foo.do{}

You can’t do in a SynthDef. I mean you can, but it only runs at SynthDef creation time, not on every audio frame. Your 10.do code only runs once, when the SynthDef is created. From the help page:

It is important to understand that although a single def can provide a great deal of flexibility through its arguments, etc., it is nevertheless a static entity. A def’s UGen graph function (and the SC code within it) is evaluated only when the def is created. Thus statements like while, do, collect etc. will have no further effect at the time the def is used to create a Synth, and it is important to understand that a UGen graph function should not be designed in the same way as functions in the language, where multiple evaluations can yield different results. It will be evaluated once and only once.

Try this to see what you’re really do-ing:

(
SynthDef(\multipadNope, {
	arg freq=100, layers=10;
	var temp, sum;
	sum = 0;
	layers.do{
		("cycle!" + layers).postln;
		temp = VarSaw.ar(freq * {Rand(0.98, 1.02)}!2, {Rand(0.0, 1.0)}!2, 0.5, 0.08,);
		sum = sum + temp;
	};
	Out.ar(0, sum);
}).add;
)

It will print cycle! an OutputProxy when you just add the synth.

(In CSound you can force a “synth” to reinit, but there’s no such facility in SC, as far as I know. Likewise for a “synth” recursively spawning copies of itself.)

1 Like