Some "reg" are accepted, while some throw errors- Scriptnode
-
I just started using the latest build of Scriptnode after using @d-healey developer build for a few months and I am seeing some truly bizarre and unexpected errors that defy logic.
As you can see from the screenshot, I have a whole lot of "reg" lines, one after the other. But, for some strange reason, it doesn't like line 303, even though it follows exactly the same logic as all of the other previous lines. It throws "error at definition".
So, when I change REG to VAR, it will accept it and throw an error for the following line, 304, which also starts with REG. So, I am having to change the lines from 303 down from REG to VAR to make it work. What's going on here @Christoph-Hart ?
It makes no sense what so ever. This code has worked great for a long time and all of a sudden half of the lines are accepted and half of them are not, following exactly the same naming logic.Let me know if you need me a provide my project to help analyze the bug.
-
You can only have 32 reg variables per namespace. I think in this instance you'd be better off making namespace enums.
For example:
namespace Drums { const var HatsTipSource = 31; const var HatsEdgeSrouce = 33; const var KickSource = 35; const var CajonLowSource = 36; }
Then you access them like this:
Drums.HatsTipSource;
.You might find my new coding standards doc helpful - https://github.com/davidhealey/hise_documentation/blob/master/scripting/scripting-in-hise/hise-script-coding-standards.md
-
Thanks @d-healey . I will check that out. When was this 32 reg limit implemented and why? This is going to be more unnecessary work
-
@gorangrooves It's always been there - https://docs.hise.audio/scripting/scripting-in-hise/additions-in-hise.html#reg-variables
Why are you using reg variables instead of const?
-
@d-healey The limit couldn't have been there always since I've had the same code for a while and it worked flawlessly. Only with the recent Scriptnode that it started to throw errors.
Why am I using the var instead of const? I think @Lindon should probably answer that since he wrote the original code
So, just replace all reg with const var and put them in a namespace?
-
So, just replace all reg with const var and put them in a namespace?
I don't know about "all", there is a reason to use reg and there is a reason to use const, choose the right one for the situation. But looking at your screenshot those values look like magic numbers so would be better as consts and a namespace would help to organise them. I also see some vars at the top of your script that should probably be const var.
The limit couldn't have been there always since I've had the same code for a while and it worked flawlessly. Only with the recent Scriptnode that it started to throw errors.
It's been there since at least 2016: https://forum.hise.audio/topic/79/scripting-best-practices
-
Thanks @d-healey I guess then that the limit wasn't enforced. Perhaps it was suggested, but now it is enforced by throwing errors. I changed most of those var into const var and it works well as you suggested. Thank you.
-
Yes, I added a check that throws an error if you exceed the 32 slots. Before it was undefined behaviour which could lead to subtle follow-up bugs.
-
@Christoph-Hart Ok, thank you. I guess this will help me keep things more solid :)