Skip to main content
Inspiring
February 14, 2024
Question

grammar of expressions

  • February 14, 2024
  • 1 reply
  • 422 views

Hi all

 

Maybe I don't know something...
You can write an expression for the position of a layer in different ways. For example like this


var TargetL = thisComp.layer("GradComp")
[TargetL.width, TargetL.height]


or so


[thisComp.layer("GradComp").width, thisComp.layer("GradComp").height]

 

When you write it for the first time, the application shows an error


TypeError: Cannot read properties of undefined (reading 'width')


But with the second version of writing, such an error does not occur...

 

 

What is the difference???

This topic has been closed for replies.

1 reply

AnyONAuthor
Inspiring
February 14, 2024

Be sure to end the token line with a semicolon (;)

ShiveringCactus
Community Expert
Community Expert
February 15, 2024

@AnyON has it right, the programming language in After Effects is a cut down version of Javascript.  Semicolons are used to end a statement in Javascript, as otherwise it reads as:

var TargetL = thisComp.layer("GradComp")[TargetL.width, TargetL.height]

Which AE would try to take as create a new variable, called TargetL and make it equal to a values in an array called thisComp.layer("GradComp") and those values are TargetL's width and height, which we've just made - in other words something not possible to process.