Message "def" not Understood

I kinda fell off with SC recently, and am forcing myself to get back into it. I was just getting too frustrated not knowing what the hell is going on because I suck at programming. But here I am! Back for more punishment. As such, I’m a little rusty. SC is definitely NOT like “riding a bike” for me.

I’m getting a Message “def” not found error when playing this:


(
SynthDef(\demand1, {
	arg out=0, gate=1, freq=400;
	var x, y, env, sig;
	env = EnvGen.ar(Env.adsr(), gate, doneAction:2);
	x=Dseq((5..20)*50,inf);
	y={ |a|
		SinOsc.ar(Demand.kr(Impulse.kr(a),0,x))
	};
	sig = SinOsc.ar([freq, freq+1]) * y.(1) * y.(3);
		Out.ar(out, sig * env);
}.play;
)
)

The code works and plays, but I can’t decipher this error.

ERROR: Message 'def' not understood.
RECEIVER:
Instance of Synth {    (000001E5DE3303F8, gc=B0, fmt=00, flg=00, set=03)
  instance variables [6]
    nodeID : Integer 1216
    server : instance of Server (000001E5D741FBE8, size=30, set=5)
    group : instance of Group (000001E5E1B59078, size=5, set=3)
    isPlaying : false
    isRunning : false
    defName : Symbol 'temp__5'
}
ARGS:
PATH: C:/SCandTidal/realsad.scd

PROTECTED CALL STACK:
	Meta_MethodError:new	000001E5DE0F8340
		arg this = DoesNotUnderstandError
		arg what = nil
		arg receiver = Synth('temp__5' : 1216)
	Meta_DoesNotUnderstandError:new	000001E5DE0FA300
		arg this = DoesNotUnderstandError
		arg receiver = Synth('temp__5' : 1216)
		arg selector = def
		arg args = [  ]
	Object:doesNotUnderstand	000001E5E0E42300
		arg this = Synth('temp__5' : 1216)
		arg selector = def
		arg args = nil
	SynthDef:addControlsFromArgsOfFunc	000001E5D70CF9C0
		arg this = SynthDef:demand1
		arg func = Synth('temp__5' : 1216)
		arg rates = nil
		arg skipArgs = 0
		var def = nil
		var names = nil
		var values = nil
		var argNames = nil
		var specs = nil
	SynthDef:buildUgenGraph	000001E5D70CF440
		arg this = SynthDef:demand1
		arg func = Synth('temp__5' : 1216)
		arg rates = nil
		arg prependArgs = [  ]
		var result = nil
		var saveControlNames = nil
	a FunctionDef	000001E5D70CDA80
		sourceCode = "<an open Function>"
	Function:prTry	000001E5D6ABE580
		arg this = a Function
		var result = nil
		var thread = a Thread
		var next = nil
		var wasInProtectedFunc = false
	
CALL STACK:
	DoesNotUnderstandError:reportError
		arg this = <instance of DoesNotUnderstandError>
	Nil:handleError
		arg this = nil
		arg error = <instance of DoesNotUnderstandError>
	Thread:handleError
		arg this = <instance of Thread>
		arg error = <instance of DoesNotUnderstandError>
	Object:throw
		arg this = <instance of DoesNotUnderstandError>
	Function:protect
		arg this = <instance of Function>
		arg handler = <instance of Function>
		var result = <instance of DoesNotUnderstandError>
	SynthDef:build
		arg this = <instance of SynthDef>
		arg ugenGraphFunc = <instance of Synth>
		arg rates = nil
		arg prependArgs = nil
	Interpreter:interpretPrintCmdLine
		arg this = <instance of Interpreter>
		var res = nil
		var func = <instance of Function>
		var code = "(
SynthDef(\demand1, {
	arg ..."
		var doc = nil
		var ideClass = <instance of Meta_ScIDE>
	Process:interpretPrintCmdLine
		arg this = <instance of Main>
^^ The preceding error dump is for ERROR: Message 'def' not understood.
RECEIVER: Synth('temp__5' : 1216)

Any help much appreciated! Thank you thank you.

The second-to-last ) is misplaced – it should be immediately after }.

// *not* this
SynthDef(\demand1, { ... }.play);

// THIS one
SynthDef(\demand1, { ... }).play;

After more time programming, you might find that you develop a kind of sixth sense about brackets – when they’re unbalanced or misplaced, it “feels” wrong. This takes time, though.

hjh

Oh my god I feel so stupid. I was hunting this for EVER. Thanks as always jamshark70. Hope you’re doing well. Next time I’m just going to re-write the code from scratch. I would have found it that way.

HAHA. And, done. After months of no SC, I come back and create this broken early 60’s sci-fi horror:


(
SynthDef(\demand1, {
	arg out=0, gate=1, freq=200;
	var x, y, env, sig, sig2;
	env = EnvGen.ar(Env.adsr(), gate, doneAction:2);
	x=Dseq((5..20)*20.midicps,inf);
	y={ |a|
		SinOsc.ar(Demand.kr(Dust.kr(a),0,x))
	};
	sig = y.(1*y.(2))
	 * SinOsc.ar([freq, freq*0.5]);
	LeakDC.ar(SinOsc.ar([freq*2+(freq/2) * y.(1) * y.(1/2),freq*2+freq * y.(1) * y.(1/4)]).fold2) * -6.dbamp;
	sig = DelayC.ar(sig, 0.005,LFNoise1.kr(Rand(4.5,10.5),0.25*0.005,0.75*0.005) );
	sig2 = (Delay1.ar(sig) + sig).fold2/2;
	sig = (sig + sig2)/2;
	Out.ar(out, sig * env);
	
}).play;
)

sorry 'bout it.