Solved How are external script files saved?
-
I moved a bunch of code out of my
onInit
script today to external scripts likeFonts.js
,Laf.js
,PresetBrowser.js
, etc. and including them withinclude("Fonts.js");
inonInit
.After more work I realized that no updates to those external scripts were being saved. I was editing the scripts in the HISE code editor by selecting them from the dropdown at the top of the editor.
When I quit and relaunch HISE the external scripts are back in the state in which I created them - whether I load either the .hip or .xml.
In case it matters - I created the external scripts by selecting the code and using the 'Move selection to external file' context menu item.
While I work I regularly save by CMD+S (confirm twice) then SHIFT+CMD+S (confirm twice) - I still don't really understand the difference but I thought that would cover all bases.
Is this a bug or is there some other save I have to perform when editing external scripts?
-
@dannytaurus Oh gosh, this is a whole can of worms. There's no command in HISE to save all open files…there's different "save" commands for different types of files in different contexts. Be careful about learning this system correctly, so you don't lose anything. [I've slightly edited my post, as these forum posts are used by folks for learning about HISE.]
- If you're editing a file in an external editor, and then click on an error in the Console, it will open the file within HISE. Once that happens, changes you save in the external editor will be overwritten. I think.
- Script files: You must compile to save them.
- Except the onInit file, which can only be saved with…SHIFT+CMD+S.
- I think the Components and Module tree are also saved with SHIFT+CMD+S.
- There's also CMD-S to save a Preset, which I've never understood the use of.
- Then, there's Archives, which you can save…no idea what they are.
- Then there's loading a Project, but no command seemingly to save one?
- There's recreating a recovery XML from…I don't know.
- There's a command to compile all scripts, which I think saves all open external scripts open in HISE tabs (but not onInit).
- There's a Preference about saving connected scripts or something or other — it's probably helpful.
- Watch out for "detached" in the tab header, which occurs when a syntax error prevents HISE from parsing the file structure. Don't change the code in any tabs that are detached — fix the error, first.
Good luck. But it's not a bug.
-
@clevername27 Crikey, no wonder I'm having trouble getting my head around it all!
-
@dannytaurus Well…
I'm sure someone will post, shortly, that I'm wrong and unreasonable(and probably am on both counts), and spell it all out in some way that probably makes a little more sense. But the source code is available, and nothing stopping any of us from improving the situation. So, I'm not complaining. Just…I dunno, it's late. -
@clevername27 I agree that the entire file management is a bit convoluted when you start out but this stems from two facts:
- I tried to separate as much as possible into multiple files so you can benefit from source control as much as possible. This results in many different ways to load / save / include stuff, but I favor this highly over having one monolith of a file like you have with .nki
- HISE is not just a code editor. It is using / caching the stuff and I have to be ridiculously cautious on what resources I'm loading so that when you export the plugin it will only embed in the binary what's required. (that's why the code editor tab situation is as annoying as it is).
That being said, there's obviously lots of room for UX improvements within these restrictions and I'm always grateful for first experience feedback of developers as most of us (myself included) have swallowed some pills that aren't strictly necessary.
To the actual question: I found the practice to save the files when you compile perfectly fine in my 12 years of using HISE (actually I'm doing the same in VisualStudio when writing C++, I don't save the files, but press F5 to compile which saves all edited files). But I understand that the habit of using the Ctrl+S shortcut in the code editor leading to anything in the entire project being saved except for the one thing that you want is bad.
-
@Christoph-Hart Thank you for your thoughtful reply. I hope it was evident that I was being humorous in my critique.
@dannytaurus, to build on @Christoph-Hart's authoritative information (he's the primary author of HISE), you're on Mac like me, whenever you want to save, if you're within HISE:
- Enable the preference for saving connected scripts.
- Whenever you've made changes to an included script that's in HISE, choose "Compile" within that tab, whether or not you're ready to compile. This is always more or less instant, so it's not a problem. The F5 Chris mentions is the same as the menu item to compile all scripts.
- Watch for "detached" in the head of a script. When you see that, there's a syntax error preventing the file structure from being parsed — don't make any changes to those files until you've resolved the syntax error. This happens in any computer language – you can thank Noam Chomsky.
- Use SHIFT-CMD-S to save everything else, including onInit.
- As with any programming environment, Use GIT or similar tool to ensure you can backtrack.
- Use an hourly backup system (as with any programming environment).
HISE can seem daunting at first, but it's very powerful, and there's a wonderful community of people who help (and people like me who seem to only vent sarcasm).
-
@Christoph-Hart @clevername27 At last I found the root of my problem.
I do have 'Save connected scripts' enabled and I am saving with CMD+S and SHIFT+CMD+S. I also thought I was compiling the scripts every time before saving, however...
I was using the 'Tools > Recompile all scripts' menu item, which apparently doesn't do what I thought it did.
Up until I started working with external scripts it worked fine but maybe that command doesn't compile external scripts?
So, now the mystery of why my scripts weren't saving is solved - and I just need to get used to pressing F5 to compile instead of my Recompile All Scripts shortcut
-
-
-
@dannytaurus wait so you‘re saying that recompile all scripts do not save the external files? Because that would be an easy fix and you wouldn‘t have to retrain your muscle memory.
-
@Christoph-Hart said in How are external script files saved?:
@dannytaurus wait so you‘re saying that recompile all scripts do not save the external files? Because that would be an easy fix and you wouldn‘t have to retrain your muscle memory.
From my testing here on
db780f4f
it does not.Video here: https://wmd.d.pr/v/2bfsSz
I edit the external script, then Recompile All Scripts from the Tools menu. The UI flashes and the external script panel flashes, like it's compiling/saving. Then I save HIP with CMD+S and save XML with SHIFT+CMD+S.
Then when I quit and relaunch then reload the XML, the edits to the external file are gone.
If it is indeed a bug and you want me to open a GitHub issue let me know.
-
@dannytaurus Alright, that's fixed now. I realized that pressing F5 in the code editor will also just save the currently edited file, which also might be confusing, so that's fixed too (I guess in my years of using HISE I never once edited a file without pressing compile afterwards)...