Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Script runs a function that doesn’t exist anymore

  • Script runs a function that doesn’t exist anymore

    Posted by Oleg Pirogov on February 8, 2019 at 9:10 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?

    Oleg Pirogov replied 7 years, 3 months ago 2 Members · 2 Replies
  • 2 Replies
  • Andrei Popa

    February 9, 2019 at 7:52 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.

  • Oleg Pirogov

    February 11, 2019 at 6:12 am

    I see… Great explanation, thank you!

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