[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [sc-users] out of scope variables when passing functions was: Re: [sc-users] SystemClock-schedAbs explodes when time arg not used?
was: Re: [sc-users] SystemClock-schedAbs explodes
when time arg not used?
--- James Harkins <jamshark70@xxxxxxxxx> escribió:
> A function is aware of variables in all enclosing
> scopes, unless the
> function defines a variable or argument having the
> same name as a
> variable in a higher-level scope.
>
> arg item ,i, at=i;
This is a one or two weeks old thread, but tinkering
with the SystemClock explode thread examples i could
manage to come up with an example that truly
reproduces the problem i was having (and is the true
reason of the other thread)
look this:
MyClassA {
*new {
^super.new.init
}
init {
}
dump { | me |
(" great "++me).postln;
}
}
MyClassB {
var <>myA;
*new {
^super.new.init
}
init {
myA = MyClassA.new;
}
play {
var k;
k = 0;
5.do{arg i;
SystemClock.schedAbs( thisThread.clock.seconds + i +
1.0 , {arg time; myA.dump( k ); nil } );
("but while i is "++i++" k is "++k).postln;
k = k + i;
}
}
}
then;
a = MyClassB.new;
a.play;
but while i is 0 k is 0
but while i is 1 k is 0
but while i is 2 k is 1
but while i is 3 k is 3
but while i is 4 k is 6
a MyClassB
great 10
great 10
great 10
great 10
great 10
So i'm getting the value of k at the time of the
execution of the scheduled function. What i want is to
pass the value of k at the time of the _scheduling_,
that is what i want *views to the heavens with a
thanks gesture*
__________________________________________________
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis!
¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar