I used to use Notepad++ a lot myself, but I've mostly moved over to using Visual Studio Code for JavaScript now, since it has a bunch of extensions to help check JavaScript for bugs and such (if you're interested, I use the ESLint, DeepScan, JSHint, and Numbered Bookmarks extensions).
Anyways, to answer your question, here's how you can load external files and have them work in Twine 2. First, put this code in your JavaScript section:
if (window.hasOwnProperty("storyFormat")) {
// Change this to the path where your HTML file is
// located if you want to run this from inside Twine.
setup.Path = "C:/Games/MyGameDirectory/"; // Running inside Twine application
} else {
setup.Path = ""; // Running in a browser
}
setup.JSLoaded = false;
importScripts(setup.Path + "YourExternalCode.js")
.then(function() {
setup.JSLoaded = true;
}).catch(function(error) {
alert("Error: Could not find file 'YourExternalCode.js'.");
}
);
Just change "C:/Games/MyGameDirectory/" to the directory where your HTML and JavaScript files are located, and change "YourExternalCode.js" to the name of the JavaScript file you want to access. Then that code can detect whether you're playing through Twine or not, and set the file path appropriately before starting to load the JavaScript file.
It's important to note that the code doesn't get loaded immediately by importScripts(), so you can check the value of "setup.JSLoaded" (set in the above code) to tell if it has loaded properly yet or not before executing any code which depends on that JavaScript. For example:
var IntervalID = 0;
if (setup.JSLoaded) {
SomeFunction();
} else {
clearInterval(IntervalID);
IntervalID = setInterval(JSWait, 100); // Starts waiting for external JavaScript to load.
}
function JSWait() { // Checks to see if JavaScript has loaded yet.
if (setup.JSLoaded) {
clearInterval(IntervalID); // Stop waiting
SomeFunction();
}
}
function SomeFunction() {
// Your code that depends on the loaded JavaScript here.
}
That code checks to see if the external JavaScript has loaded yet or not, and if it hasn't, then it waits until it has before triggering the "SomeFunction()" function.
Also note that in your external files you'll need to put "SugarCube." in front of SugarCube functions and properties. So if you had code that used "State.variables" to get SugarCube variables, then in the external JavaScript version you'd have to do "SugarCube.State.variables" instead.
Hope that helps! :-)