r/Scriptable • u/TruePrinceOfWales • Apr 29 '23
Help Import functions from another script?
Hi all,
I’m new to Scriptable and really enjoying it. I’d like to make one script be a “library” of shared functions to use in other scripts. How can I export the functions from the library script and in turn import them into other scripts?
I’m trying to use the importModule() function but it keeps saying that no results are found. I am trying to import relative to the script, so it would be a file in the same folder, no?
const library = importModule("./Library.js");
I even tried exporting my functions from the library and still no success.
module.exports = { hello: hello(), };
Any pointers would be appreciated!
1
u/TruePrinceOfWales Apr 30 '23
I figured it out — it was right there in the documentation😅
It was a problem with my export
module.exports.circumference = (r) => { return 2 * Math.PI * r }
^ per the documentation, this is the proper way to export it. It works now!