ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Script runs a function that doesn't exist anymore

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Oleg Pirogov
Script runs a function that doesn't exist anymore
on Feb 8, 2019 at 9:10:05 pm

So there's a script:

function a(){
alert("lol");
}

a()


I run it, then delete the function declaration:

a()

The app still runs it as if the declaration is still there. Feels like it caches the function somewhere but I don't know really.
Cache cleaning doesn't help.
Restarting AE does help (i.e. it gives "function is undefined error").

How does it work actually and how can I force AE not to do that?


Return to posts index

Andrei Popa
Re: Script runs a function that doesn't exist anymore
on Feb 9, 2019 at 7:52:20 am

Once you run a script, all the variables that are global are saved in memory until you restart your engine(AE here, but could be extendscript, illustrator etc). In order to not have this problem, you need to store your variables locally. To do that, the best practice in my opinion is use this kind of code as a frame for yours:

(function myScript(thisObj){

//here you write your code

})(this)

This function calls on itself, and all the variables you have are stored inside it. So when it stops running, you have no variable "leftover".
As a fun fact. You can actually use a variable from a script into another script if it is stored globally.

I hope i answered your question.

Andrei
My Envato portfolio.


Return to posts index

Oleg Pirogov
Re: Script runs a function that doesn't exist anymore
on Feb 11, 2019 at 6:12:25 am

I see... Great explanation, thank you!


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2019 CreativeCOW.net All Rights Reserved
[TOP]