Skip to main content
Adirai Maji
Inspiring
December 29, 2019
Answered

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

  • December 29, 2019
  • 1 reply
  • 285 views

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????

This topic has been closed for replies.
Correct answer Justin Taylor-Hyper Brew

Your second script is overwriting your first one when the names are the same, that's why you're having that issue. Also, you're polluting the Global Namespace which is very bad as it can cause problems with your scripts, and other people's scripts. To avoid this, wrap your scripts in an IIFE statement like this:

 

(function(){
    // Your Code Here
})();

 

And spend some time learning about how scope works in Javascript, it's a core aspect to programming:

https://www.w3schools.com/js/js_scope.asp

1 reply

Justin Taylor-Hyper Brew
Community Expert
Community Expert
January 3, 2020

Your second script is overwriting your first one when the names are the same, that's why you're having that issue. Also, you're polluting the Global Namespace which is very bad as it can cause problems with your scripts, and other people's scripts. To avoid this, wrap your scripts in an IIFE statement like this:

 

(function(){
    // Your Code Here
})();

 

And spend some time learning about how scope works in Javascript, it's a core aspect to programming:

https://www.w3schools.com/js/js_scope.asp