Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions parseInt boolean value

  • parseInt boolean value

    Posted by Oscar Nyquist on December 9, 2021 at 1:02 pm

    Hello,

    I’m using a source text property to control a boolean expression (in this case, to set auto leading on a text layer). I know I can just use 0/1 in my source text, but I would like to be able to use true/false instead.

    Here’s what I have:

    aL = thisComp.layer("orderData").text.sourceText.split(",")[3];
    GEN = style.setAutoLeading(aL);

    The string being extracted from the source text is simply the word “true”. However, it still gives me an error, I assume because AE can’t parse the string as a boolean value.

    Is there an easy way to parse the boolean value from the source text property and insert it directly into my setAutoLeading expression? I could of course use an IF statement to get around the issue, but I would like to check first if I’m missing a simpler solution.

    Thanks!

    Oscar Nyquist replied 4 years, 8 months ago 3 Members · 4 Replies
  • 4 Replies
  • Andrei Popa

    December 9, 2021 at 1:05 pm

    You could simply check if the word is “true” by changing the second line to

    GEN = style.setAutoLeading(aL == "true");

    If the word is anything else but “true”, auto leading is set to false.

  • Oscar Nyquist

    December 9, 2021 at 1:12 pm

    Thank you for the quick reply!

    That’s a good workaround. Do you have any idea about whether what I asked about initially is simply impossible within the limitations of JS?

    That is, if there’s any way to parse a non-numerical string into a boolean value? Would be good to know for future reference.

  • Dan Ebberts

    December 9, 2021 at 5:21 pm

    I guess you could parse it with eval(), like this:

    aL = eval(thisComp.layer("orderData").text.sourceText.split(",")[3]);
  • Oscar Nyquist

    December 10, 2021 at 3:27 pm

    Cool, thank you very much!

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