(Possible) Breaking change: local variables references inside nested function definitions
-
@danh said in (Possible) Breaking change: local variables references inside nested function definitions:
if (hr.toString(2) == ".hr1")
Magic number alert!!! You should use
hr.toString(hr.OnlyExtension)
-
@danh said in (Possible) Breaking change: local variables references inside nested function definitions:
ok so just:
Yes, but it's no longer scoped now so you can change that comment ;)
Also
hr
does exist at init so you can't assign the value there, you have to do that within your function like you were before. -
@d-healey said in (Possible) Breaking change: local variables references inside nested function definitions:
Also hr does exist at init so you can't assign the value there, you have to do that within your function like you were before.
with 'var'?
-
@danh I'd say use a reg but if Christoph says a var is okay then var is ok. My point was you have
reg origin = hr
at the top of your script now, buthr
doesn't exist until yourFileSystem.browse
call, so you can't assign it when you declare theorigin
variable at the top of your script you have to assign it after the call tobrowse
just like you were withlocal origin = hr
now you just putorigin = hr
. Or do what Christoph said. -
This post is deleted! -
@d-healey said in (Possible) Breaking change: local variables references inside nested function definitions:
Magic number alert!!! You should use hr.toString(hr.OnlyExtension)
Right, changing to the above makes the install process stop before the window appears allowing me to select the destination for the samples. So... select the .hr1 file and then nothing more...
-
@danh Oo could be that the constant is bugged. I'm away from the computer for the next day so can't test, stick to your magic number for now :)
-
hr
was already external, right? so why bother using another variableorigin
for the same thing in the first place?
It might be me, everyone around is telling me I need glasses... Arfff... 44... might be the time anyway... -
@ustk hr comes from the file browse call but the scope doesn't extend to the second browse call so it needs to be stored in a temporary variable
-
Just to say that I updated my custom branch, and all my
var
changed tolocal
in the current project that is dependent on this very custom branch.
It's not a big deal to change back everything though as I remember this fix. But in the case it can be fixed it could help other people not to have this surprise, without knowing where it comes from :) -
This post is deleted! -
@ustk Same here. I've used tons of local variables in all of my projects. Now this shit comes...
-
@orange This problem was always there, it's just now you get a warning. It only applies to local variables in certain circumstances.
-
@d-healey said in (Possible) Breaking change: local variables references inside nested function definitions:
@orange This problem was always there
My previous projects can't be opened with the latest develop branch.
But if I modify thelocal
variables asvar
it works. So this issue is a new one. -
But if I modify the local variables as var it works. So this issue is a new one.
No it's an old issue, but now there is a new error so it might cause problems with opening old projects.
You don't need to change all
locals
tovar
- in fact that is a really bad idea. You only need to change the ones that are in nested functions. And I recommend not changing them tovar
because that pollutes the scriptwide namespace, I think it's better to create areg
object at the top of each namespace that can be used to hold the values - should I make a video about this? -
@d-healey Ok I will try with
reg
thanks.So only modifying the places that the Hise gives the warnings is enough? Or even Hise doesn't give warnings, I should modify all nested functions?
-
Ok I will try with reg thanks.
Just 1
reg
at the top of the namespace.I should modify all nested functions
Only nested functions (not inline functions) that are affected by this issue. The issue is that the variables go out of scope in certain circumstances. For example if you are calling something like
Engine.showYesNoWindow()
The callback function that you pass to that function will be triggered after any local variables have already been destroyed.So it's basically anywhere you are using a callback function. A few examples would be:
Engine.showYesNoWindow()
Server.downloadFile()
File.extractZipFile()
FileSystem.browse()
FileSystem.browserForDirectory()
-
I am just trying to understand the case about what to do here. I have a script like below and I am getting
Cannot define local variables outside of inline functions or callbacks.
error in Hise - the current develop branch.inline function onMYGENERICFUNCControl(component, value) { local myLocalOne = Engine.getSystemTime(); local myLocalTwo = Engine.getVersion(); local myLocalThree = Engine.showYesNoWindow(); if(value) { // Execute a function } else { // Execute a function } }; Content.getComponent("MYGENERICFUNC").setControlCallback(onMYGENERICFUNCControl);
So Should I transform the local variables with namespace & reg combination like this? Is this an effective usage?
namespace myNamespaceFunc { reg myLocalOne; reg myLocalTwo; reg myLocalThree; inline function onMYGENERICFUNCControl(component, value) { myLocalOne = Engine.getSystemTime(); myLocalTwo = Engine.getVersion(); myLocalThree = Engine.showYesNoWindow(); if(value) { // Execute a function } else { // Execute a function } }; Content.getComponent("MYGENERICFUNC").setControlCallback(onMYGENERICFUNCControl); };
-
@Steve-Mohican You shouldn't be getting an error there, that is an inline function. Are you sure that is where the error is being generated?
-
@d-healey Yes I am getting that error exactly there.
I am also using a
Server.callWithGET()
inside the if statement and using these 3 variables in the if statement but I just trimmed the code to make it more clean