call function inside function
-
I have this:
inline function onBTNControl(component, value) { // a lot of code function scroll() { // a lot of code } // Here is my reference to the "scroll" function like this: onBTNControl.scroll = scroll; }
It's working nicely if I have been running the first BTN function once
But I am unable to get to the inner function if the first has not been executed.
Is there a better way to script this?Can I declare the inner function outside of the BTNfunction?
How? -
Declaring functions inside functions doesn't seem like a good idea. And declaring a non-inline function inside an inline function would seem to be to defeat the advantages of using an inline function.
Declare each function separately.
-
@d-healey I want the inner function to execute only inside the other function to avoid using globals.
The inner function use variables that only exists inside the outer function -
@ulrik This is what namespaces are for.
-
@d-healey So how do I set it up, do you have a short example where both functions use the same "private" variables?
-
There are no private variables in javascript or HISE script. But in HISE script we can create variables that have scope limited to a namespace.
namespace MyNamespace { reg myVariable = 50; inline function aFunction() { Console.print(myVariable); // Will print 50 to the console } } Console.print(MyNamespace.myVariable); // Will print 50 to the console Console.print(myVariable); // Will trigger undefined parameter error�
Note that the variables must be of type reg or const to limit the scope. var will always be global.
More info here:
https://forum.hise.audio/topic/92/namespaces-in-javascript
https://github.com/davidhealey/hise_documentation/blob/master/scripting/scripting-in-hise/hise-script-coding-standards.md -
@d-healey Thank you David, I will study :)
-
@d-healey if you create a pull request for the coding standard, I'll merge it into the main doc branch so it becomes part of the HISE doc website.
-
@Christoph-Hart Done, thanks!
-
Ah damn, I noticed you were using a Markdown feature that the HISE Markdown parser is not supporting (inline code examples in a bullet list):
- This list item has a code example: ```javascript CodeExample ``` - Next Item
This makes it look like this in the HISE doc browser:
With a bit of whitespace correction it looks like this:
However then it might not look as good in the Github preview. Hard choice :)
-
@Christoph-Hart I think it's more important that it looks good in the HISE docs since that's where I expect most users will find it. Do you want me to clean it up?
-
Nope, I'll do it, I have to add the metadata and stuff anyways. It's a pretty quick thing...
-
Alright here we go:
https://docs.hise.audio/scripting/scripting-in-hise/hise-script-coding-standards.html
I noticed that in some examples it uses 2 spaces instead of a tab (=4 spaces) now. Should be an easy fix though :)
-
@Christoph-Hart Thank you!