Highlighted

Issue using IF statements as part of SourceText output

New Here ,
Jun 14, 2020

Copy link to clipboard

Copied

I am trying to create a template where I can control the prefixes and suffixes surrounding a numeric value within the SourceText of a text layer e.g. $10M or £5K.

(The suffix and prefix inputs would be controlled by Expression Controls > Dropdown Menu Controls.)

 

I have managed to succesfully write the individual prefix and suffix expressions (see below), but they fail when combined or when I try and add the value between them.

 

Problem 1 - Getting both if statments to appear

If I exclude the value, but include both if statements, only the last if statement appears e.g. expecting $M, I would only see the M suffix.

 

Problem 2 - Error when adding in a Value

When I try and add  the numeric Value inbetween the Prefix and Suffix IF statements, using the + symbol, I get the error "illegal use of the reserved word if".

 

So I feel I am missing something to combine these 3 values together (as they work separately). I even tried making both IF statements their own variables, but I got the "illegal use of the reserved word if" error again. The only other workaround is for me to do if statements for every combination of suffix and prefix (but that isn't very scalable if I want to add more symbols on the future).

Any help on this would be appreciated.

 

//variables
v = ((thisComp.layer("Control layer").effect("Y Axis Value")("Slider")).value);
prefix = thisComp.layer("Control layer").effect("Y Axis - Prefix")("Menu");
suffix = thisComp.layer("Control layer").effect("Y Axis - Suffix")("Menu");

//Combined Prefix + Value + Suffix code
//prefix expression
if(prefix == 1){''} else if(prefix == 2){'$'} else if(prefix == 3){'£'} else if(prefix == 4){'¥'} else if(prefix == 5){'€'} else if(prefix == 6){'₹'};

//value
+ v +

//suffix expression
if(suffix == 1){''};else if(suffix ==2){'K'};else if(suffix ==3){'M'};else if(suffix ==4){'B'};else if(suffix ==5){'T'};

 

TOPICS
Expressions

Views

112

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Issue using IF statements as part of SourceText output

New Here ,
Jun 14, 2020

Copy link to clipboard

Copied

I am trying to create a template where I can control the prefixes and suffixes surrounding a numeric value within the SourceText of a text layer e.g. $10M or £5K.

(The suffix and prefix inputs would be controlled by Expression Controls > Dropdown Menu Controls.)

 

I have managed to succesfully write the individual prefix and suffix expressions (see below), but they fail when combined or when I try and add the value between them.

 

Problem 1 - Getting both if statments to appear

If I exclude the value, but include both if statements, only the last if statement appears e.g. expecting $M, I would only see the M suffix.

 

Problem 2 - Error when adding in a Value

When I try and add  the numeric Value inbetween the Prefix and Suffix IF statements, using the + symbol, I get the error "illegal use of the reserved word if".

 

So I feel I am missing something to combine these 3 values together (as they work separately). I even tried making both IF statements their own variables, but I got the "illegal use of the reserved word if" error again. The only other workaround is for me to do if statements for every combination of suffix and prefix (but that isn't very scalable if I want to add more symbols on the future).

Any help on this would be appreciated.

 

//variables
v = ((thisComp.layer("Control layer").effect("Y Axis Value")("Slider")).value);
prefix = thisComp.layer("Control layer").effect("Y Axis - Prefix")("Menu");
suffix = thisComp.layer("Control layer").effect("Y Axis - Suffix")("Menu");

//Combined Prefix + Value + Suffix code
//prefix expression
if(prefix == 1){''} else if(prefix == 2){'$'} else if(prefix == 3){'£'} else if(prefix == 4){'¥'} else if(prefix == 5){'€'} else if(prefix == 6){'₹'};

//value
+ v +

//suffix expression
if(suffix == 1){''};else if(suffix ==2){'K'};else if(suffix ==3){'M'};else if(suffix ==4){'B'};else if(suffix ==5){'T'};

 

TOPICS
Expressions

Views

113

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Jun 14, 2020 0
Most Valuable Participant ,
Jun 14, 2020

Copy link to clipboard

Copied

Your code is pretty much nonsense. There is no fallback condition by ways of a simple else{}, the statements are interrupted by semicolons, the actual return values are not written to a variable and I have no idea what your value is even supposed to do in the position where it is. Strings are still concatenated in the form stringA+v.toString(v)+stringB and in your case stringB hasn't even been evaluated at this point. This hasn't anything to do with AE, that's basic JavaScript stuff.

 

 

//prefix expression
if(prefix == 1){mPref=''}
else if(prefix == 2){mPref='X'}
else{mPref='Error'};

//suffix expression
if(suffix == 1){mSuf=''}
else if(suffix == 2){mSuf='Y'}
else{mSuf='Error'};

mPref+v.toString()+mSuf

 

 

Mylenium

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 14, 2020 0
murphdjs LATEST
New Here ,
Jun 16, 2020

Copy link to clipboard

Copied

Many thanks for your feedback and solution - this has helped me increase my knowledge levels about JavaScript, which were zero a week ago 🙂

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 16, 2020 0
New Here ,
Jun 16, 2020

Copy link to clipboard

Copied

I found a workaround:

I moved my existing individual expressions for suffix and prefix into 2 respective separate layers. I then combined them back into the main layers source text with the value sandwiched in-between.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 16, 2020 0