Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions code troubleshooting

  • code troubleshooting

    Posted by David Markey on July 10, 2015 at 3:33 pm

    Hi all. The solution here is probably very simple. AE keeps telling me there’s an error in line 7. “expected: ;.”

    I referred to this site for syntax (https://www.w3schools.com/js/js_if_else.asp), and I think all my semi-colons are in place. What did I miss?

    Background Info: We create a lot of ‘trivia question’ animations. Text layers display a question with multiple choices for answers. After a period of time, the correct answer glows. I want this expression to automatically position the glow adjustment layer over the correct answer so I don’t have to manually change it every time.

    I figure I’ll apply it to the glow adjustment layer’s position property. The idea is that the expression checks to see which of the multiple choices has the same source text as the ‘correct answer’ layer (text layer with visibility off) and then positions the adjustment layer to it.

    The expression:

    ANSWER1 = thisComp.layer(“Answer 1”).transform.position;
    ANSWER2 = thisComp.layer(“Answer 2”).transform.position;
    ANSWER3 = thisComp.layer(“Answer 3”).transform.position;
    ANSWER4 = thisComp.layer(“Answer 4”).transform.position;
    GLOW = transform.position;

    If (comp(“3 – Answer 1”).layer(“Answer 1”).text.sourceText = thisComp.layer(“Answer”).text.sourceText){
    GLOW = ANSWER1;
    }
    else If (comp(“4 – Answer 2”).layer(“Answer 2”).text.sourceText = thisComp.layer(“Answer”).text.sourceText){
    GLOW = ANSWER2;
    }
    else If (comp(“5 – Answer 3”).layer(“Answer 3”).text.sourceText = thisComp.layer(“Answer”).text.sourceText){
    GLOW = ANSWER3;
    }
    else {
    GLOW = ANSWER4;
    }

    David Markey replied 11 years ago 2 Members · 6 Replies
  • 6 Replies
  • Dan Ebberts

    July 10, 2015 at 3:50 pm

    The only thing that jumps out at me is that your logical comparisons in your if statements should use “==” instead of “=”. I don’t know if that’s responsible for the error message though.

    Dan

  • David Markey

    July 10, 2015 at 4:25 pm

    Thanks for response, Dan. I revised the code as follows:

    If (comp(“3 – Answer 1”).layer(“Answer 1”).text.sourceText == thisComp.layer(“Answer”).text.sourceText){
    GLOW = ANSWER1;
    }

    I still get the error though, so it must be something else.

  • Dan Ebberts

    July 10, 2015 at 4:37 pm

    Ah, OK–you’re using “If” instead of “if” and “else If” instead of “else if”.

    Dan

  • David Markey

    July 10, 2015 at 4:59 pm

    wow, thanks! i can see now, learning more coding will be a long hard road of 1000 ‘gotchas’.

    the expression is no longer broken, but i can’t get the layer to reposition to the right place. It defaults to Answer 4, indicating that the source text doesn’t match, even though I copy/pasted.

    What could be throwing it off?
    Is there a better property to reference than sourceText?
    Is there some code to ‘standardize’ the text so the expression is more likely to view them as equal?

    Backstory: The end goal is to revise hundreds of these questions using Spreadsheets and the AE script openSesame.

  • Dan Ebberts

    July 10, 2015 at 5:16 pm

    Usually when you reference “text.sourceText” the expression engine assumes you want the value, but sometimes it decides that you want the sourceText object, which may be what’s happening here. Try replacing all those references with “text.sourceText.value”.

    Dan

  • David Markey

    July 10, 2015 at 6:20 pm

    awesome. that worked.

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy