ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

If/Then Statement for comparing two values in same text

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Sascha Kaliga
If/Then Statement for comparing two values in same text
on May 23, 2018 at 10:05:05 am

Hey guys, I'm running into a wall and can't figure out how to create this expression, hope you can help me.

I have one text layer called Score which says 2 - 5.
What I want to do now is to add a fill color to the text and change the whole text to red if the first value in the score is lower than the second one.

I tried doing it with textsource.split, but I only got syntax errors. Hope you guys can help me.


Return to posts index

Dan Ebberts
Re: If/Then Statement for comparing two values in same text
on May 23, 2018 at 5:50:17 pm

One way would be to add a Fill Color RGB Animator, add an Expression Selector, and add this expression for Amount:

txt = text.sourceText.split("-");
score1 = parseInt(txt[0],10);
score2 = parseInt(txt[1],10);
if (score1 < score2) 100 else 0


Dan



Return to posts index

Sascha Kaliga
Re: If/Then Statement for comparing two values in same text
on May 24, 2018 at 7:07:43 pm

Hello Dan, thank you for your reply! I tried the expression, but I get an error in error 3 saying the array of [1] couldn't be found.


Could you help me?


All the Best,

Sascha


Return to posts index


Dan Ebberts
Re: If/Then Statement for comparing two values in same text
on May 24, 2018 at 7:09:52 pm

That probably means your text doesn't have a hyphen character in it.

Dan



Return to posts index

Sascha Kaliga
Re: If/Then Statement for comparing two values in same text
on May 24, 2018 at 7:25:49 pm

Hm that's weird, the text has a hyphen (it's "2 - 0"). I only don't get a syntax error if I remove everything in the split option (so it only says "").


All the Best,

Sascha


Return to posts index

Dan Ebberts
Re: If/Then Statement for comparing two values in same text
on May 24, 2018 at 8:30:25 pm

I'm sorry, what do you mean by "everything"? There should only be a hyphen in there.

Dan



Return to posts index


Sascha Kaliga
Re: If/Then Statement for comparing two values in same text
on May 24, 2018 at 9:43:46 pm

Hey Dan, I tried as split options ("-"), (" - "), (" ") and (""). Only the last one (without anything, not even a space) doesn't give me an expression error, all other variants tell me array [1] is missing.


Return to posts index

Dan Ebberts
Re: If/Then Statement for comparing two values in same text
on May 24, 2018 at 10:18:57 pm

The only thing I can think of is that maybe the hyphen in the expression is a different character than the one in your text. Try copying the one from your text into the expression.

Dan



Return to posts index

Sascha Kaliga
Re: If/Then Statement for comparing two values in same text
on May 25, 2018 at 8:20:20 am

Ah thank you Dan, that was it! The hyphen in the score is slightly longer. Thank you very much!


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 CreativeCOW.net All Rights Reserved
[TOP]