ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

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

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Adirai Maji
Scripting : I've noticed something weird in scripting. Can anyone Explain why and how this is happening?
on Dec 29, 2019 at 1:58:00 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


Return to posts index

Dan Ebberts
Re: Scripting : I've noticed something weird in scripting. Can anyone Explain why and how this is happening?
on Dec 29, 2019 at 8:34:55 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



Return to posts index

Tomas Bumbulevičius
Re: Scripting : I've noticed something weird in scripting. Can anyone Explain why and how this is happening?
on Jan 2, 2020 at 12:55:15 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


Return to posts index


Dan Ebberts
Re: Scripting : I've noticed something weird in scripting. Can anyone Explain why and how this is happening?
on Jan 2, 2020 at 5:26:46 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



Return to posts index

Tomas Bumbulevičius
Re: Scripting : I've noticed something weird in scripting. Can anyone Explain why and how this is happening?
on Jan 3, 2020 at 6:45:21 am

Dan, that is exactly what I was asking - thank you a ton!

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


Return to posts index

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