2 Replies Latest reply on Apr 14, 2010 7:05 AM by mpd323

    prevent function access between 2 scripts




      I have a understanding problem with InDesign JavaScript Engine.

      I have two simple Scripts.


      Script 1:



      function random (max) {
          return Math.floor (Math.random() * max);


      Script 2:



      If I execute the Script 1 it is works fine.

      If I execute the Script 2, it finds the function "random" from the Script 1.

      How I can prevent this ?

      I have tested #targetengine, #engine and #script.




        • 1. Re: prevent function access between 2 scripts
          Marc Autret Level 5

          If you execute Script1, then Script2, in the same persistent engine, the function random that you declare in Script1 is available in Script2.


          What's the problem?


          Do you need to use a different random function in Script2?


          You may add a #targetengine 'Script1' directive in Script1, and a #targetengine 'Script2' directive in Script2, to separate each process. (In this case, random need to be defined in Script2).


          If you use the same #targetengine, you can ‘overwrite’ random in Script2 by using something like:


          this.random = function() {/*Script2 random stuff*/}


          but that's probably not what you want...


          Finally, what don't you use random1 in Script1 and random2 in Script2?

          If you really need two distinct functions, create two distinct functions!

          • 2. Re: prevent function access between 2 scripts
            mpd323 Level 1

            Hello Marc,


            this was a little sample with random(). I have a lot of Scripts. And they have functions with same Names. And some functions are little different. The JavaScript Engine use sometimes the functions from Script1 and sometimes from Script2. I have tested with #targetengine and it is the same result.