Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Scripting : I’ve noticed something weird in scripting. Can anyone Explain why and how this is happening?

  • Scripting : I’ve noticed something weird in scripting. Can anyone Explain why and how this is happening?

    Posted by Adirai Maji on December 29, 2019 at 1:58 pm

    I’ve created two different scripts to do two different tasks. In both scripts I’ve dialog boxes.

    I call the dialog function with same function name since they’re two different sctipts I didn’t had a thought that they meshup with each other. When I click the dialog button on each script they work fine…..Until one of the scripts not being running in After Effects. But If I run both script’s UI on AE and press the dialog button on either of those scripts it only pops up dialog which is related to one script. I’ve resolved this issue by changing the function name of one dialog box.

    Why is this happening? What If I want to use same function name on two different scripts????

    ==================================================================================================
    Thanks in Advance…

    – Adirai Maji

    Tomas Bumbulevičius replied 6 years, 4 months ago 3 Members · 4 Replies
  • 4 Replies
  • Dan Ebberts

    December 29, 2019 at 8:34 pm

    An easy way to keep from cluttering AE’s namespace with your function names is to make sure everything in enclosed in a single function with a unique name, like this:


    function AndiraiMaji_01(){

    // your script here

    }
    AndiraiMaji_01();

    Dan

  • Tomas Bumbulevičius

    January 2, 2020 at 12:55 pm

    Hey Dan, in such scenario – could you suggest what is the best way to treat global variables? Because if there are some affected variables inside the function, they will stay local within that ‘custom’ function. \

    Should it be done by building object of variables to be returned or is there a better way?

    Thanks!

    Find out more:
    After Effects Tutorials: motion design, expressions, scripting.
    Boxer – Dynamic Text Boxes Template with a Live Preview

  • Dan Ebberts

    January 2, 2020 at 5:26 pm

    That depends on what you mean by global. When I want something to be accessible from anywhere within my script, I declare an object just inside my enclosing function, like this:


    function de_NewScript(){

    // globals

    var G = new Object();
    G.scriptName = "Dan's New Script";\

    // functions

    function myUtilityFunction(){
    // function code here
    }

    // main code

    }
    de_NewScript();

    But if I need something global that two scripts can use to communicate, I would generally attach it to the app (maybe not recommended, but it seems to work):

    app.de_object = {};
    app.de_object.script1Present = true;

    Dan

  • Tomas Bumbulevičius

    January 3, 2020 at 6:45 am

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