# How long is too long?



## Mike Greene (Dec 7, 2010)

I haven't had any problems yet, but as I'm finishing this up and starting to combine various elements, should I be concerned about a script that will be in the 3,000 line neighborhood?

I can't imagine that's as long as some of the big boys' scripts, but if it's likely to cause problems, now would be the time for me to spend some extra time splitting it up and using more of those interscript PGS commands (which are pretty darn handy.) This is all under the assumption that a few smaller scripts are easier for Kontakt to handle than one gigantic one. I wonder if that's actually correct, or if I just imagined that?

Also, it appears Kontakt now has "functions." I didn't really read that section very carefully, because I'm perfectly happy doing my functions the old fashioned way in Nils' Script Editor, which I assume still expands them out when it compiles the script. Is there any reason why I should change and start using Kontakt's built in functions now?


----------



## Dynamitec (Dec 7, 2010)

Don't worry...I'm in the neighborhood of 20.000 and more lines per script. No problem at all. The only limit is that the on init callback may 'only' contain 5000 lines (if I recall correctly).


----------



## Mike Greene (Dec 7, 2010)

Dynamitec @ Tue Dec 07 said:


> Don't worry...I'm in the neighborhood of 20.000 and more lines per script. No problem at all. The only limit is that the on init callback may 'only' contain 5000 lines (if I recall correctly).





Lindon @ Tue Dec 07 said:


> Yep, I'm up well past 12,000 lines in some of the GridMachine instruments now so you should be fine...nice to know 20K+ is still working too...



Hey, thanks for making me feel like a big wimp, guys! :mrgreen: 

I kinda figured a lot of scripts were much bigger than mine, but this is good to know for sure. 8)


----------



## Lindon (Dec 7, 2010)

yep 12K lines of KSP script...ouch my head hurts...

this is what it looks like now....


----------



## EvilDragon (Dec 8, 2010)

Looking pretty good, Lindon!

Well, perhaps the LEDs on FX buttons could've been antialiased better  Otherwise, neat!


----------



## kotori (Dec 8, 2010)

Mike Greene @ Tue Dec 07 said:


> Also, it appears Kontakt now has "functions." I didn't really read that section very carefully, because I'm perfectly happy doing my functions the old fashioned way in Nils' Script Editor, which I assume still expands them out when it compiles the script. Is there any reason why I should change and start using Kontakt's built in functions now?



Hi Mike,
Here is my advice: if you have a function that is invoked from somewhere else than the init callback, does not take any parameters, and does not call built-in functions that are only available in certain callbacks (eg. allow_group/disallow_group) then I would suggest that you use the new call keyword. It will make the compiled code shorter and also cut down on the time it takes to compile the script in KScript Editor. In other cases you can use the old way of inlined functions, except if there is some specific case where using the "call" keyword would lead to significant savings in terms of the number of lines of code - in that case one can write a little wrapper around the _call_ed function to make it possible to use parameters and return values.



Dynamitec @ Tue Dec 07 said:


> Don't worry...I'm in the neighborhood of 20.000 and more lines per script. No problem at all. The only limit is that the on init callback may 'only' contain 5000 lines (if I recall correctly).


I don't think there is any limit except from the parser stack limit that applies to all callbacks. If you run into problems with the parser stack limit you can just add an "if (1=1)" to turn flat structures into nested - that solves it. I just tested with 15 000 lines in the init callback and it worked well.

Btw. I wish I could have shown you guys what the sky look liked this cold morning at my place. It was an amazing halo - three suns in the sky. Almost as impressive as http://bit.ly/gOXqCg (this one) (photo taken by someone else in Sweden in 2009). I wish I had brought a camera.

Cheers,
Nils


----------



## EvilDragon (Dec 8, 2010)

Woah Nils, that's a very beautiful sight, even though it's not what you saw! Awesome, almost equaling the beauty of aurora borealis!


----------



## Dynamitec (Dec 8, 2010)

WOW!!! What a photo!


----------



## Dynamitec (Dec 8, 2010)

You can have 4992 lines in all callbacks (no if constructs as workaround), till you get a parser stack overflow. I assume thats way I have the 5000 number in my head.

In Kontakt 3 the limit was 992 lines, so it has been risen significantly (K3 => K4).


----------

