DazScript import external script file?
shoei321
Posts: 113
Simple question -- I've built a library of utility functions located in a file "tools.dsa". I want to include that script from another Daz script so that I can call the functions in it. How do I do this?
I've tried :
import("tools.dsa");
No error, but my functions aren't available from the calling script. I've dug around DazScript and QTScript docs but can't seem to find an answer. I found the DzScript object but that doesn't appear to be what I need.
Thanks
Post edited by shoei321 on
Comments
-Rob
...but what if the imported DAZ script is in a random DAZ content directory? The code below seems to work, but...
...does it fall foul of the "...should not be called within a nested scope and it should not be called inline" criteria?
(P.S. Of course, the '// Do more stuff' involves calling the functions from the included file)
An alternative, if you want to execute a script, is to use DzScript - that lest you load a script (DzScript.loadFromFile( name ) ) as an object and modify or execute it. The include command is like the equivalent directive in C or BASIC - it expands the included code and runs it as part of the flow of the script (it's there to avoid duplication of code that needs to be used in multiple scripts without modification).
Thanks Richard, using DzScript seems to work fine.
But now I want to pass parameters to the script, so I use 'Boolean execute (Array args)' as per the DAZ Script 2: DzScript docs:
I just can't work out how to pick up those parameters in the called script!
:roll:
getArguments() returns the parameters as an array.
* Thread Necro Warning*
I know this one is old, but I decided to start to move several of my commonly used functions and objects into separate files, just to test if it works, and works likej a charm, including .dse (encrypted files) as well.
Needed to be put outside the wrapper
and no wrapper on the included files, but then it do work. Maybe Rob the Wizard knows why but that is how I interpreted his post ^^up there too.
My God! Is this a magic?
I tried to load another .dse in my script but it doesn't work, cost me few hours to find an answer, at beginning I saw your post but don't understand what you mean, but, after long time can not find out another answer, I tried yours, and it works! Unbelievable, what an includeDir comes from.
Puting it in a wrapper (an anonymous function) limits the scope of all items in the script to the called scopt because the wrapper is anonymous and cannot be called from elsewhere (except, I think, vasriables which are not properly declared, which are universal in scope, but I am not certain that applies) so that they do not bleed through into the calling script. Without the wrapper everything that is at the top level in the script is global through the calling script.