Forums › Adobe After Effects Expressions › using if else to set a variable
-
using if else to set a variable
-
Adam Greenberg
October 19, 2022 at 2:16 pmHi everyone, simple question I think,
Is my 5th line of code correct ?
I am trying to set this variable into a complicated expression, so I did not bother to paste the whole thing, only the problematic line.
Basically I want ”a” to be a variable depending on which layer in the precomp is turned on;
title=precomp1.source.layer(“title”);
title2=precomp1.source.layer(“title 2 lines”);
b=title.sourceRectAtTime();
c=title2.sourceRectAtTime();
if(comp(“precomp”).layer(“title”).active) var a = b else var a = c;
Thanks so much
-
Dan Ebberts
October 19, 2022 at 3:20 pmThe JavaScript engine won’t accept if/else on a single line in that format. I’d do it like this:
a = comp("precomp").layer("title").active ? b : c;
-
Adam Greenberg
October 19, 2022 at 4:14 pmoh ok. Thanks so much Dan
Viewing 1 - 3 of 3 posts
Log in to reply.