recalling Array values doesn't work as expected

Jun 12, 2011 at 12:05pm

recalling Array values doesn't work as expected

Hi,
i’m only able to recall the values of the Array testi2 when n = 1. Why?
I saved all reopened it but same behavior.

testi1 = new Array(“a”,”b”,”c”)
testi2 = new Array(“x”,”y”,”z”)

function simp(n,s)

{
post (n);
post (s);

if (n=1) {n = testi1;}
if (n=2) {n = testi2;}

post (n[s]);
post (“n”);

}

– Pasted Max Patch, click to expand. –
#57561
Jun 12, 2011 at 1:33pm

You are setting a variable rather than doing a comparison in your if statement. You basically set n to 1 and then immediately set it again to two so and thereby only ever reference the second array. Try changing those two lines so you use == instead of = like so:

if (n==1) {n = testi1;}

#206229
Jun 12, 2011 at 1:33pm

You are setting a variable rather than doing a comparison in your if statement. You basically set n to 1 and then immediately set it again to two so and thereby only ever reference the second array. Try changing those two lines so you use == instead of = like so:

if (n==1) {n = testi1;}

#206325
Jun 12, 2011 at 3:05pm

lol…thanks Luke.

#206230
Jun 12, 2011 at 3:05pm

lol…thanks Luke.

#206326

You must be logged in to reply to this topic.