[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [sc-users] Env.levels problem - unexpected post window output
Hi
You need to use the copy message. Basically, assignment is by
reference. If you want a distinct object, use -copy.
http://doc.sccode.org/Classes/Object.html#Copying
(
~wenv = Env(
levels: Array.fill(3, {arg j; j}),
times: Array.fill(2, {arg j; 1/2;}),
curve: \lin
);
("~wenv before:" + ~wenv.levels).postln;
~tempenv = ~wenv.copy;
~tempenv.levels = ~tempenv.levels*2; // update
("~wenv after:" + ~wenv.levels).postln;
("temp:" + ~tempenv.levels).postln;
)
vdom.kunz@xxxxxxxxxxxxxx writes:
> Dear All,
>
> I am stuck with the following pretty simple problem...
>
> (
> ~wenv = Env(levels: Array.fill(3, {arg j; j}), times: Array.fill(2,
> {arg j; 1/2;}), curve: \lin);
> ("~wenv before:" + ~wenv.levels).postln;
>
> ~tempenv = ~wenv;
> ~tempenv.levels = ~tempenv.levels*2; // update
>
> ("~wenv after:" + ~wenv.levels).postln;
> ("temp:" + ~tempenv.levels).postln;
> )
>
> where the console output is...
>
> ~wenv before: [ 0, 1, 2 ]
> ~wenv after: [ 0, 2, 4 ]
> temp: [ 0, 2, 4 ]
> -> temp: [ 0, 2, 4 ]
>
> I expected the following:
>
> ~wenv after:[ 0, 1, 2 ], or in other words ~wenv not to be modified.
>
> I take it, it is me again having an issue with the concept of classes, no?
>
> Many thanks in advance
>
> Dominik
>
>
>
> _______________________________________________
> sc-users mailing list
>
> info (subscription, etc.):
> http://www.birmingham.ac.uk/facilities/ea-studios/research/supercollider/mailinglist.aspx
> archive: https://listarc.bham.ac.uk/marchives/sc-users/
> search: https://listarc.bham.ac.uk/lists/sc-users/search/
>
--
CYa,
⡍⠁⠗⠊⠕
_______________________________________________
sc-users mailing list
info (subscription, etc.): http://www.birmingham.ac.uk/facilities/ea-studios/research/supercollider/mailinglist.aspx
archive: https://listarc.bham.ac.uk/marchives/sc-users/
search: https://listarc.bham.ac.uk/lists/sc-users/search/