DazScript import external script file?

shoei321shoei321 Posts: 106

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 :


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.


Post edited by shoei321 on


  • rbtwhizrbtwhiz Posts: 1,402
    edited December 1969

    void include( String scriptPath )

    Includes the contents of scriptPath in the same context as the calling script. This function should only be called within the global scope of the script; it should not be called within a nested scope and it should not be called inline. As a safeguard against circular references, the script engine keeps an internal list of unique paths for included scripts; per script context, per execution. Each time the function is called, scriptPath is checked against the list to ensure that the path has only been included once within the context of the script.

    scriptPath - The path of the script to include. The path is assumed to be relative to the ./scripts directory. Absolute paths are also supported.


  • 3dcheapskate3dcheapskate Posts: 1,318
    edited June 2013

    ...but what if the imported DAZ script is in a random DAZ content directory? The code below seems to work, but...

    while (i<=n && sFile=="")
    { s=App.getContentMgr().getContentDirectoryPath(i++)+"/scripts/ScriptName.dsa";
     oNewFile = new DzFile(s);
     if (oNewFile.exists())
    if (sFile!="")
     include (sFile);
     // Do more stuff
     MessageBox.warning("Unable to find ScriptName.dsa. Terminating.", "TITLE", "&OK;", "" );

    ...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)

    Post edited by 3dcheapskate on
  • Richard HaseltineRichard Haseltine Posts: 43,339
    edited December 1969

    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).

  • 3dcheapskate3dcheapskate Posts: 1,318
    edited December 1969

    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:

     o_Script = new DzScript(sFile); 
     o_Script.execute( ["Parameter-String1","Parameter-String2"])

    I just can't work out how to pick up those parameters in the called script!

  • Richard HaseltineRichard Haseltine Posts: 43,339
    edited December 1969

    getArguments() returns the parameters as an array.

Sign In or Register to comment.