Activity › Forums › Adobe After Effects › Global variables for expressions.
-
Global variables for expressions.
Posted by Michael Tammaro on August 12, 2014 at 9:23 pmConsider the following two expressions, which might be applied to two different layers:
(1) x = A*Math.cos(6*time); y = 600; [x,y]
(2) x = A*Math.cos(12*time); y = 600; [x,y]
Is there a way to set the value of A globally, so that I don’t have to exit each expression every time I change A?
John Cuevas replied 12 years ago 2 Members · 6 Replies -
6 Replies
-
John Cuevas
August 13, 2014 at 1:33 amMake “A” a variable that’s linked to a slider on a control null layer.
Null layer named “Control”:
A = thisComp.layer("Control").effect("Slider Control")("Slider");
x = A*Math.cos(12*time); y = 600; [x,y]Johnny Cuevas, Editor
Thinkck.com“I have not failed 700 times. I have succeeded in proving that those 700 ways will not work. When I have eliminated the ways that will not work, I will find the way that will work.”
—THOMAS EDISON on inventing the light bulb. -
Michael Tammaro
August 13, 2014 at 6:17 pmJohnny, thank you!
If I have, say, 5 variables, do I need to create five null layers–one for each variable?
-
John Cuevas
August 13, 2014 at 7:23 pmYou could put all the sliders on one Null control layer. When I made that A variable, I just picked whipped to it, but each expression slider will have a different name “slider” “slider 2″…so you could type it in if you wanted, just need to get the naming correct.
Also you can rename the slider Control itself if that will make things easier, for instance, you could rename your slider control–position control and your expression would look like:
A = thisComp.layer(“Control”).effect(“position control”)(“Slider”);
Hope that helps you out, I only know the basics of expressions.
Johnny Cuevas, Editor
Thinkck.com“I have not failed 700 times. I have succeeded in proving that those 700 ways will not work. When I have eliminated the ways that will not work, I will find the way that will work.”
—THOMAS EDISON on inventing the light bulb. -
Michael Tammaro
August 13, 2014 at 8:07 pmExcellent. Thanks.
Sorry to be so needy, but I’m getting a syntax error in the following expression:
x0 = 865; y0 = 525; r1 = Math.sqrt((745 – x0)*(745 – x0) + (660 – y0)*(660 – y0)); r2 = Math.sqrt((895 – x0)*(895 – x0) + (660 – y0)*(660 – y0)); o1 = thisComp.layer(“on1”).effect(“Slider Control”)(“Slider”); o2 = thisComp.layer(“on2”).effect(“Slider Control”)(“Slider”); l = thisComp.layer(“Wavel”).effect(“Slider Control”)(“Slider”); f = thisComp.layer(“Freq”).effect(“Slider Control”)(“Slider”); A = thisComp.layer(“Amp”).effect(“Slider Control”)(“Slider”); s1 = o1*A*Math.cos(2*Math.PI*r1/l – 2*Math.PI*f*time); s2 = o2*A*Math.cos(2*Math.PI*r1/l – 2*Math.PI*f*time); st1 = (x0 – 745)/r1; ct1 = (660 – y0)/r1; st2 = (x0 – 895)/r1; ct1 = (660 – y0)/r2; x = s1*st1 + s2*st2; y = s1*ct1 + s2*ct2; [x,y]
-
Michael Tammaro
August 13, 2014 at 8:41 pmIt has something to do with the square root, because I’m getting an error with this one too:
x0 = 1; y0 = 2; r1 = Math.sqrt((745 – x0)*(745 – x0) + (660 – y0)*(660 – y0)); x = r1 + x0; y =r1 + y0; [x,y]
-
John Cuevas
August 14, 2014 at 2:27 amAt this point, I’m out of my depth, so I’m going to refer you to the Expressions Forum, the guys there are a lot more experienced than me.
Johnny Cuevas, Editor
Thinkck.com“I have not failed 700 times. I have succeeded in proving that those 700 ways will not work. When I have eliminated the ways that will not work, I will find the way that will work.”
—THOMAS EDISON on inventing the light bulb.
Reply to this Discussion! Login or Sign Up