Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Noob Question — Specifying X and Y

  • Noob Question — Specifying X and Y

    Posted by Tito Long on April 3, 2024 at 12:11 pm

    Hi there. I’m going through the book ‘After Effects — The Power of Expressions’ and keep getting stuck on something in my head.

    It’s a section about writing an expression that limits your position to round numbers,

    x = position[0];
    y = position [1];
    [Math.round(x),Math,round(y)];

    my question is why does the [0] and [1] appear in square brackets like this? Is it because it’s pulling from the first and and second position coordinates that are an array, so they have be called out in square brackets?

    And secondly, why are (x) and (y) called out in regular bracket and not called out in square brackets?

    Any help much appreciated!

    Tito Long replied 11 months, 3 weeks ago 2 Members · 2 Replies
  • 2 Replies
  • Dan Ebberts

    April 3, 2024 at 1:40 pm

    Yes, multi-dimension property values are stored as JavaScript arrays, so to access the individual elements you use JavaScript’s square bracket array notation. Once you have those values stored in local one-dimensional variables (x and y in this case) you wouldn’t use array notation with those. The brackets in Math.round(x) are associated with the Math.round() function, and have nothing to do with x or y. It’s all core JavaScript syntax. Hope that helps.

  • Tito Long

    April 3, 2024 at 2:02 pm

    Yes, that answers exactly what I was wondering. Thank you for replying!

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