data.getStaticData
A function added to MapTool Macro Script to work with data. Currently, the only type of data stored is for Add-On Libraries, but this will be expanded in the future. This can be used to access text files, JSON, or even images within the add-on. Images are returned in the asset:// format so they can be used in image tags.
Usage:
data.getStaticData(namespace, path)
If called from outside of the Add-on, getStaticData() can only access files in the library/public/ directory. For example, to display the contents of a testData.txt file in the chat window, make sure testData.txt is in the library/public/ directory and type:
[r: data.getStaticData("icarean.0001.Time_tracker", "public/testData.txt")]
If called from within the code of the Add-on, getStaticData() can only access files in the library/ directory and subdirectories. For example, to display the contents of a testData2.txt file in a directory library/example/ from one of the Add-on's macros, use this line is the macro:
[r: data.getStaticData("icarean.0001.Time_tracker", "example/testData2.txt")]
Notes:
- Do not include the library/ directory name in the path passed to getStaticData()
- The 'Export Library Token as Addon' tool turns each token property into a file in a property/ directory. As per above, that directory cannot be accessed by getStaticData() - the files will need to be moved into the library/ directory or a subdirectory of library/ (e.g. library/public/ if desired to access from outside the Add-on)
- If getStaticData() is unable to access the the file (e.g. if trying access a directory other than public/ from outside of the Add-on, or if the directory/file doesn't exist), no output will be produced.
- The full namespace must be written (as defined in the Add-on's library.json file); you cannot use "this" as the namespace - trying to do so will produce the error: "Library with namespace this does not exist."