Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

New Premium Module: Tyrants of the Moonsea! Read More
Attention, new and old users! Please read the new rules of conduct for the forums, and we hope you enjoy your stay!

Setting up an external script compiler in Visual Studio Code.

To answer some obvious questions:
1. Why would you do this?
Convenience: Develop in a professional, dedicated and current programming environment.
Robustness: Crashes in the toolset do not affect the scripting environment and vice-versa.
Switch focus: Go into the toolset and check resrefs / tags without having to close the script editor first.
Easy integration with Git if you want to collaborate.

2. Does it cost anything?
No, just a few minutes to set up.

3. I'm a real Man/Woman/Alien so I use Linux, will this work for me?
In theory yes, but you will need to sort out building the script compiler and extracting your files from your module.
Please feel free to ask in this thread, but don't expect me to be the one answering. :-)

4. OK, I'm in, how do I do it in Windows?

a) Install Visual Studio Code (VSC):
https://code.visualstudio.com/download
Follow the instructions.

b) Get some nice formatting:
Open VSC and Ctrl+Shift+x to open the Extensions panel
In the search bar at the top of the panel, delete all the stuff there and type in: nwscript
Install that.

c) Find all the files:
I have a pretty standard steam install, so hopefully if I show you where my files are you can figure it out. Remember this bit for later.

The game gets installed here:
C:\Program Files (x86)\Steam\steamapps\common\Neverwinter Nights
If you decided to install your game in Z:\Steamie, then go look there, you should be able to find the same file structure.

That is all the stuff that BD own, you don't want to mess with it as it can and, hopefully, will change with future patches. But you will need to know about it for later....

Your stuff goes here:
C:\Users\***YOUR USER NAME***\Documents\Neverwinter Nights

d) Get a compiler:
This would be the tricky bit, except some genius has already done it for us:
https://neverwintervault.org/project/nwn1/other/tool/nwnsc-nwn-enhanced-edition-script-compiler

Unzip this and get the file nwnsc.exe and put it in your directory:
C:\Users\***YOUR USER NAME***\Documents\Neverwinter Nights\modules

e) Get started with VSC
Open it up.
Ctrl+Shift+E will make sure you have the Explorer tab open on the left.
Put your mouse in some blank space there and right click to be able to select "Add Folder to WorkSpace" and then select:
C:\Users\***YOUR USER NAME***\Documents\Neverwinter Nights\modules

You should now be able to see the contents of your modules directory in the Explorer panel on the left.

In VSC go to the file menu at the very top and select Save Workspace, then give it the file name nwn_vsc click save.

Open File->Preferences->Settings and click on WORKSPACE SETTINGS at the top.

Replace the file with this:
{ "folders": [ { "path": "modules" } ], "settings": { "files.exclude": { "**/*.are": true, "**/*.dlg": true, "**/*.exe": true, "**/*.fac": true, "**/*.gic": true, "**/*.git": true, "**/*.ifo": true, "**/*.itp": true, "**/*.jrl": true, "**/*.mod": true, "**/*.ncs": true, "**/*.utc": true, "**/*.ute": true, "**/*.uti": true, "**/*.utp": true, "**/*.uts": true } } }

CTRL S to save it... don't forget! This will stop you seeing a big list of stuff you really don't want to edit.

Next, add the compiler to VSC:
Top menu in VSC, Tasks->Configure Tasks and select the Create tasks.json file from template entry. Replace everything you see on screen with the following and CTRL+S to save it.

If you already use VSC and have tasks defined, just manually open your tasks.json file and add this to it.

{ // See https://go.microsoft.com/fwlink/?LinkId=733558 // for the documentation about the tasks.json format "version": "2.0.0", "tasks": [ { "label": "NWNSC Script Compiler", "type": "process", "args": [ "-n", "C:\\Program Files (x86)\\Steam\\steamapps\\common\\Neverwinter Nights", "${file}" ], "problemMatcher": { "fileLocation": [ "relative", "${workspaceFolder}/temp0" ], "pattern": { "regexp": "(.*?(?=(?:\\()|$))\\((.*?)\\): (Warning|Error): (.*)", "file": 1, "line": 2, "severity": 3, "message": 4 } }, "command": "nwnsc", "presentation": { "reveal": "always", "panel": "new" }, "group": { "kind": "build", "isDefault": true } } ] }

Notice the path to the Neverwinter Nights installation? Update that if your's is different (don't forget to \\ for each \ you see in your path.

CTRL S to save it... don't forget!

Almost there!

File->Preferences->Keyboard Shortcuts
Click the tiny link at the top that says keybindings.json

In the keybindings.json file replace it with this:
// Place your key bindings in this file to overwrite the defaults [ { "key": "F9", "command": "workbench.action.tasks.runTask", "args": "NWNSC Script Compiler" } ]

CTRL S to save it... don't forget!

Party time.

Start your NWN Toolset and load up a module.

Start VSC and browse into the temp0 directory in the explorer pane.

Click your script file(s) and enjoy. F9 compiles the current file.

Hopefully, you can see that you can add a compile-all option to the task list if you want by replacing ${file} with something like "./temp0/*.nss" I suggest you add that as a separate task so you have a choice. I posted this as I thought it was a nice way to work and also because I suck at RegEx, so it took me ages to figure out the warning/error trap and others may as well profit from that. If I've made a mistake, sorry, please post and I'll try to resolve.

NeverwinterWightsfot1StrawMan
Sign In or Register to comment.