getScriptFileName() alternative?

Is there an alternative to getting the current script file name? Because getScriptFileName() keeps returning an empty string.

Comments

  • DafaDafa Posts: 97
    edited July 2021

    Nevermind. 

    For some reason, if you don't assign it to a variable it won't return anything.

    It doesn't return anything until the script is evaluated...rats! I can't call it at the start of my script!

    Post edited by Dafa on
  • DafaDafa Posts: 97
    edited July 2021

    Ok, now I officially figured it out.

    So um... don't have anything else in the first line, not even comments. :\

    // I'm a baloney// DAZ Studio version 4.15.0.2 filetype DAZ Scriptconst x = getScriptFileName();print(x); // returns ""

     

    Post edited by Dafa on
  • OmnifluxOmniflux Posts: 361

    I'm not sure how you are testing, but IIRC, getScriptFileName() works on scripts that are either loaded or saved  -  but not modified.

    I don't know what's happening inside DS, but from the outside it looks like once you modify a script in the script pane, a new anonymous DzScript object is created for you to work with, until you save, at which point this function should work. Once you make a change, it is once again duplicated into a new anonymous DzScript object.

    Does this match with what you are seeing?

  • OmnifluxOmniflux Posts: 361
  • DafaDafa Posts: 97

    Omniflux said:

    I'm not sure how you are testing, but IIRC, getScriptFileName() works on scripts that are either loaded or saved  -  but not modified.

    I don't know what's happening inside DS, but from the outside it looks like once you modify a script in the script pane, a new anonymous DzScript object is created for you to work with, until you save, at which point this function should work. Once you make a change, it is once again duplicated into a new anonymous DzScript object.

    Does this match with what you are seeing?

    I tested the function in another script - and it initially didn't work (which is why I commented); but after reloading the script in the Script IDE, it returned the script's absolute path. What I ended up doing after crying a river - was copying and pasting the code into a new file and hit Execute, and all of a sudden it worked. I did a file comparison to see what was different between the two scripts, the only difference was the ASCII Daz Header at the top.

    So, what I originally had was something like this:

    // I'm a baloney// DAZ Studio version 4.15.0.2 filetype DAZ Scriptconst x = getScriptFileName();print(x); // returns ""

    As you can see, it returns nothing if you try to execute it in the Script IDE, Debugger, or any other way.

    But when I did this:

    // DAZ Studio version 4.15.0.2 filetype DAZ Scriptconst x = getScriptFileName();print(x); // returns script absolute path - YAY!

    It worked.

     

    Yes, I did notice that the function would return nothing if you executed the script while the file was modified outside of DAZ or not saved; but not updated in the Script IDE. However, if you opened in (for example) the Content Library, it would work like it's supposed to.

    I just tested it again today and all of this still applies. It's amazing what a comment can do ;D

  • cridgitcridgit Posts: 1,757
    edited May 2022

    Redacted

    Post edited by cridgit on
Sign In or Register to comment.