Hello everyone, Nick here. This is the first video lesson
in the expressions and scripts module of the Superpower 2 course.
In this introductory lesson, we'll go over the basic concepts of expressions in After Effects
and find out what resources can help us.
I'll say right away that this expressions module is supplementary to the main course,
so I won't be covering the most basic expressions in After Effects from scratch.
However, in this module, we will touch upon the most common and frequently used expressions.
But for the most part, this entire section will be dedicated to specific use cases of JavaScript in After Effects.
So, what will we cover in the expressions module?
First, we'll learn what expressions and scripts are and how they differ from each other.
We'll review the most basic and frequently used expressions.
We'll learn to use interpolation and pass values from one property to another.
We'll cover how to use velocity and speed.
We'll create delays and animation offsets using valueAtTime.
We'll also use regular expressions to replace a few words in a large block of text without clicking on each one.
As a bonus, we'll go over sourceText again.
We'll be appending, rounding, and creating counters.
We'll learn how to use sourceRectAtTime to create automatic text boxes.
For fans of automation, we'll create a couple of fades using inPoint and outPoint.
We'll also play around with markers and create animation without using keyframes.
Finally, we'll talk about optimization, the most common errors in expressions, and how to solve them...
...and discuss when you should write expressions and when you shouldn't.
And for dessert, we'll write our own script panel for After Effects using ExtendScript.
First, let's talk about the new features in AE 2019.
They've updated the expressions engine.
It's a full-fledged JavaScript V8 for Windows and JavaScriptCore for Mac.
Both of these engines are modern versions of JavaScript.
They are faster and more efficient than the old ExtendScript.
There are some changes, including a few critical ones
where, for example, old expressions will no longer work.
But overall, almost the entire syntax of the old engine is supported by JavaScript.
Besides, you can always go to Project Settings, in the Expressions tab, and change the engine
from JavaScript to Legacy ExtendScript.
By the way, the old script engine is set as the default.
Let's go over the main critical changes that have appeared.
And the first one is how the if/else syntax differs.
So, if this kind of syntax used to work, especially when you're using checkboxes,
now it won't work.
Now you either write it like this, or use these brackets,
or use this with switch statements.
You can no longer just use 'this'.
You now need to specify 'thisLayer' or 'thisComp'.
You can't just leave 'this' by itself.
It won't be processed.
And the third thing I want to note is that snake_case is no longer supported.
Expressions that used underscores now must use camelCase.
The word starts with a capital letter.
Why is this important? Because you might find a very old script, say, from 10-15 years ago,
where properties and methods are written with an underscore like this.
Now, if you see such an underscore, just replace it with a capital letter, and the expression will work.
And besides the engine change in the 2019 version, they also introduced some other changes.
For example, they changed the font.
As you can see, it's now more readable compared to the previous version.
Now you can disable expressions for multiple layers at once from the context menu.
Just find Switches and then Disable Expressions.
Previously, this could only be done with scripts, but now they've finally added it to the menu.
They also added the ability to hide the error banner.
So in the After Effects settings, you can either show the banner that contains errors or remove it completely.
But of course, I recommend you leave it on, otherwise you simply won't know what errors you have and why something is working or not.
And now, after that dry information about how the old version differs from the new one and what new features were added, let's move on to what expressions are and how they differ from scripts.
Many beginners confuse these concepts and say that expressions are scripts, and scripts are expressions.
And most likely, this is because expressions are essentially written in the JavaScript language, and they hear 'script' and think, 'Oh, a script.'
So, scripts are expressions, and expressions are scripts. But that's not the case.
Indeed, expressions and scripts share the same JavaScript engine.
But expressions work inside After Effects and access methods and properties within the program.
They are quite limited in functionality and don't have access to many of the features available in After Effects.
Unlike scripts. In Russian, it's better to call them 'scenarios'.
Even the official After Effects user guide says that scripts are essentially scenarios.
This way, you won't confuse expressions, which work inside After Effects, with scripts, which need to be run separately.
Because a scenario is essentially a sequence of commands that tells After Effects to perform specific operations.
For example, select several layers, set specific parameters for them, create something.
Scenarios and expressions are launched differently.
For example, to run an expression, you just need to type an expression into the expression field, and it will work if it's written correctly.
But to run a scenario, i.e., a script, you need to either go to File > Scripts > Run Script File...
...or run it from the Window menu if it's a dockable script,
or from KBar...
...if you have snippets here, which are pieces of code, you can run it directly from here.
By the way, to avoid future questions, this panel is an extension called KBar.
It's launched separately under Extensions, and here you can find KBar if you've installed it.
KBar is an extension that adds your own custom icons, and you can assign various functions to them...
...directly from its settings window, or...
...you can write your own custom things and use them.
It's quite extensible and scalable.
You can dock it, but sometimes when After Effects is thinking or loading a frame,
all the extensions installed in After Effects do this annoying thing where they resize.
Meaning, if you have KBar docked, let's say, somewhere over here...
...or somewhere else. So it's kind of hidden, everything's fine, you're working.
Then After Effects starts to think, and this window pops out every time, and you have to keep dragging it down, down, down, down.
So I got tired of that, and I always keep it as an undocked menu.
I hope, I hope we've settled the KBar issue and won't return to it, because it's a very flashy menu compared to the rest of the After Effects interface.
What resources will we need to understand expressions in detail?
We have the official 'Expression basics' guide from After Effects. It's in Russian...
...and the translation is pretty good. It has many examples of how a particular method, property, or function works.
So I recommend you at least skim through it.
There are two guides here: one is called the 'Expression language reference,' and the other is just 'JavaScript basics.'
You can start with 'Expression basics' and then move on to the language reference.
There's also a Russian-language site called AE Expressions.
Here you can find a bunch of different examples, including some quite complex ones, and even examples with scripts.
And for my two fans, there's a special place; you can search for expression tutorials on my website.
You just need to type 'expressions' into the search bar to find some examples, both old and new.
Great, let's keep working.
And before we continue, I'll turn off this function.
See you in the next lesson.