Problem with "include()"

Hi,

As I understand it, the 'include()' function can only be used outside of the anonymous function that we're supposed to use for starting scripts.  For example:

include("C:\Users\fred\OneDrive\Scripts\My DAZ Library.dsa");

(

function() {

// My code starts here

}

)( )

This bothers me mainly because if I define functions/objects in "My DAZ Library.dsa", I have to somehow make sure that the names of those functions

don't clash with whatever global variables/functions that already exist.  How do I do that?  Do I invent some strange, annoyingly long names which

are simply unlikely to ever be used by the DAZ devs?  Is there a more elegant solution to this problem?

Comments

  • Richard HaseltineRichard Haseltine Posts: 100,843

    The included scripts would generally be by you, Daz doesn't provide a library.

    Also, you don't have to use an anonymous function as a wrapper - arrow code is frowned on but prfectly functional, or you can use named functions and invoke one by name from the global context to start the ball rolling. The main point, as I understand it, is that you can test for a stop condition and exit a function, but in the main code you have to test for the absence of a stop condition and then nest the continuing code, whichj can be hard on the eyes.

  • HowieFarkesHowieFarkes Posts: 607
    edited June 6

    You can put your own library of functions inside an object and use it like a namespace. This way you will avoid clashes.

    For example:

    var MyTools = { MyFunc1: function() { ... ; }, MyFunc2: function( param ) { ... ; } }; 

    So in your code you just use it like:

    MyTools.MyFunc2( "text" ); 

     

    Post edited by HowieFarkes on
  • Stretch65Stretch65 Posts: 166

    Thanks, Howie.  I eventually realised this was the way to go.

Sign In or Register to comment.