Problem with "include()"
![Stretch65](https://secure.gravatar.com/avatar/4ac8e70dacce16d2ff5a602d714c5cf0?&r=pg&s=100&d=https%3A%2F%2Fvanillicon.com%2F4ac8e70dacce16d2ff5a602d714c5cf0_100.png)
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
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.
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:
So in your code you just use it like:
Thanks, Howie. I eventually realised this was the way to go.