I have a script that loads a json file from a custom defined folder within my FMOD project directory. I am writing my script as
var data = studio.system.getFile("New Folder/MyText.txt")
Sometimes the script runs without any problems, but sometimes it will throw an error of
QIODevice::read (QFile, "New Folder/MyText.txt"): device not open
So how does this function work? Is there a more stable way of using relative paths in Studio Scripting API?
The working directory of studio.system.getFile()
should be the install directory of FMOD studio, and not of your project directory. If you wish to access a file in your project directory, the easiest way would be use studio.project.filePath
, which is the location of the project .fspro
, and then do some string manipulation to get the project directory:
var projectDir = studio.project.filePath;
projectDir = projectDir.substr(0, projectDir.lastIndexOf("/") + 1);
That said, unfortunately I haven’t been able to reproduce the error you’re observing. Can I get your to post the full script, or a stripped-down version where you can still reproduce the error, here for me to take a closer look at? Also, what version of FMOD Studio are you using?