[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [sc-users] dynamic variable values



hi jeremy.
what are you trying to do?
if you are trying to access variables with an index,
is there a reason not to use an array for that?

(
var vview = [20, 21, 22];
vview[0].postln;
vview[1].postln;
vview[2].postln;
)


for the code you posted below to work you will need to declare the variable within the interpreted string

this works
(

	("var vview_0 = 20;
	vview_"++0).asString.interpret.postln;
)

if you do have a need for names rather than array slots, you can try to work with Environment or IdentityDictionary:

(
var d;
d = Environment.new;
d.put(\vview_0, 20);
d.put(\vview_1, 21);
d.use{"~vview_" ++ 1.asString.interpret.postln}
)

cheers,
tom

On 28 Dec 2005, at 19:30, Jeremy Rotsztain wrote:


hello sc-list,

i'm having a modest syntax problem, which i'm hoping somebody can shed some light on.

i'm trying to dynamically access the value of a variable (identifier) by interpreting a string and a number as demonstrated below.

(

	var vview_0 = 20;
	
	//"vview_"++0.asSymbol.postln;
	//["vview_"++0].asString.compile.postln;
	
	("vview_"++0).asString.interpret.postln;


)

searching through the list and some old code, i got the impression that i should be using interpret, but that didn't do the trick. i always get the following error:

Variable 'vview_0' not defined.

thanks,

jeremy

www.mantissa.ca

_______________________________________________
sc-users mailing list
sc-users@xxxxxxxxxxxxxxx
http://www.create.ucsb.edu/mailman/listinfo/sc-users

..................................
 www.tomtlalim.tk
  www.club-mtk.tk
 www.tangiercluj.tk
..................................