Expressions/Scripts/Presets

Moderators: Disciple, zlovatt

 
charles art
Topic Author
Posts: 2
Joined: Sun Nov 11, 2007 12:01 pm

set variable via index

Sun Nov 11, 2007 12:37 pm

Hi. I have a bunch of layers with the "circle"-effect applied on it. I have a "control"-layer with 4 defined colors. The aim is:

Layer1: color1
Layer2: color2
Layer3: color3
Layer4: color4
Layer5: color1
Layer6: color2
...(and so on)

This is my lousy try, but it doesn't work:

(applied on the color option of the circle effect)
var a = ('1','5',...);
var b = ('2','6',...);
var c = ('3','7',...);
var d = ('4','8',...);

if (thisLayer.index=a){
thisComp.layer("control").effect("color1")("color")
}
else if (thisLayer.index=b){
thisComp.layer("control").effect("color2")("color")
}
else if (thisLayer.index=c){
thisComp.layer("control").effect("color2")("color")
}
else{
thisComp.layer("control").effect("color4")("color")
}

I am looking for an expression that works for every layer, independently from the number of layers or colors.
 
Dan Ebberts
Posts: 318
Joined: Sat Jun 26, 2004 10:01 am
Location: Folsom, CA
Contact:

Sun Nov 11, 2007 12:55 pm

This should work:

thisComp.layer("control").effect("color" + index)("Color")


Dan
 
Mylenium
Posts: 139
Joined: Wed Jul 20, 2005 12:07 am

Re: set variable via index

Thu Nov 15, 2007 2:39 am

charles art wrote:
Hi. I have a bunch of layers with the "circle"-effect applied on it. I have a "control"-layer with 4 defined colors. The aim is:

Layer1: color1
Layer2: color2
Layer3: color3
Layer4: color4
Layer5: color1
Layer6: color2
...(and so on)

This is my lousy try, but it doesn't work:

(applied on the color option of the circle effect)
var a = ('1','5',...);
var b = ('2','6',...);
var c = ('3','7',...);
var d = ('4','8',...);

if (thisLayer.index=a){
thisComp.layer("control").effect("color1")("color")
}
else if (thisLayer.index=b){
thisComp.layer("control").effect("color2")("color")
}
else if (thisLayer.index=c){
thisComp.layer("control").effect("color2")("color")
}
else{
thisComp.layer("control").effect("color4")("color")
}

I am looking for an expression that works for every layer, independently from the number of layers or colors.


I'd do it completely differently. You could simply use the modulus with a divisor of 4 (%4) as the criteria

if (index%4 == 0)
{color a}
else if ((index+1)%4 == 0)
{color b}
else if ((index+2)%4 == 0)
{color c}
else {color d}

Would be more flexible than hacking in all indizes first.

Mylenium
[Pour Mylène, ange sur terre]
 
charles art
Topic Author
Posts: 2
Joined: Sun Nov 11, 2007 12:01 pm

Re: set variable via index

Tue Nov 20, 2007 11:17 am

Mylenium wrote:
[

I'd do it completely differently. You could simply use the modulus with a divisor of 4 (%4) as the criteria

if (index%4 == 0)
{color a}
else if ((index+1)%4 == 0)
{color b}
else if ((index+2)%4 == 0)
{color c}
else {color d}

Would be more flexible than hacking in all indizes first.

Mylenium


Cooooool, that's exactly what I wanted. Thank you very much, Mylenium!

Who is online

Users browsing this forum: No registered users and 2 guests