Long script on K4

VST, AU, AAX, CLAP, etc. Plugin Virtual Instruments Discussion
Post Reply New Topic
RELATED
PRODUCTS
Kontakt

Post

Hi everybody

Is there a way to short the following cases with a "WHILE" or something (like with a IF and $count := $count +8), because the script I'm working now is getting very loooong...

Code: Select all

select ($test)
	case 0
		%whatever[$count] := $something
	case 1
		%whatever[$count +8] := $something
	case 2
		%whatever[$count +16] := $something
	case 3
		%whatever[$count +24] := $something
	case 4
		%whatever[$count +32] := $something
	case 5
		%whatever[$count +40] := $something
	(and it continues until case 127)
end select
Thanks

Post

From that example; put it in a lookup table?

%whatever[$count + lookuptable[case]] := $something
my other modular synth is a bugbrand

Post

Never did kontakt script stuff so I dunno this syntax but if you're trying to set values in a table based on some test you did...

Code: Select all

%whatever[$count + ($test*8)] := $something
But that's if $test is some acceptable type for the array. And I guess if there's no way to do inline typecast you prolly gotta make sure $test and $count are the same type before you try that... got no f*ckin clue about any of that in kontakt scripts sorry. Now you might wanna avoid switch cases unless you got a ton of unique cases. Iterating numbers up like that? Just throw the value into your array there. But make sure you won't go out of range cus you're gonna hate what happens, so check validity and all that first. It'd be something like...

Code: Select all

{somewhere you declare whatever...}
declare $WHATEVER_MAX := 128 {...or whatever %whatever's size is supposed to be}
declare %whatever[$WHATEVER_MAX]
{...}
declare $i := ($test*8) + $count
if ($i > ($WHATEVER_MAX - 1))
   $i := ($WHATEVER_MAX - 1)
end if
%whatever[$i] := $something
Last edited by Armagibbon on Wed Aug 09, 2017 9:07 pm, edited 6 times in total.

Post

Yeah, it would be what Armagibbon wrote.

BTW Armagibbon, they are the same type. $ denotes integer variable in KSP.

Also I assume this is being done in a while loop (that's what $count variable implies, sort of), so as long as boundary for the while loop is set properly, there shouldn't be array overflow.

Post

Makes sense. Might wanna use a uint type or something for counting and all that... I gotta learn this shit man. Is the nils tutorial a good place for starters?

Post

KSP reference is good for starters (PDF comes installed with Kontakt).

KSP doesn't have unsigned ints. :P Just 31-bit signed ints ($), int arrays, same 31-bit signed (%), strings (@), string arrays (!), floats (~) and float arrays (?). The last two only from version 5.6 onward.

Post

Kickass thanks! Had no idea about the official docs... gonna learn me some ksp now hahaha

Post

Awesome! thanks to all of you for the quick response :tu:

Post

How about this one?

Code: Select all

		if ($count >= 20)
			select ($count)
				case 20 to 29
					$count := $count -20
					$something := 0
				case 30 to 39
					$count := $count -30
					$something := 1
				case 40 to 49
					$count := $count -40
					$something := 2
				case 50 to 59
					$count := $count -50
					$something := 3
				case 60 to 69
					$count := $count -60
					$something := 4
				case 70 to 79
					$count := $count -70
					$something := 5
				case 80 to 89
					$count := $count -80
					$something := 6

				{and continues until $something := 127
			end select

Post

This doesn't make sense much. Why would you decrease $count by decades? Why not run $count from 0 to 9 instead (yields the same thing)?

You should probably say what you want to do exactly, then we can suggest the most efficient way to loop it. But really, you should rely more on simple math than select-case!

Post

Of course it does have sense; its for a menu, like its done on the dynamitec FXScript. $something is every different item group added with +10 and etc. This is for when its selected.

Post

It's quite hard to deduce what you want to do without larger scope (like, the whole callback).

Post

You know man it's def a good call to follow evil dragon's advice there. If you're gonna jump by numbers bigger than 1, you gotta define that value somewhere else and use math to include it in whatever logical stuff you're trying to do here. Because you WILL want to change that value later and it's best to change it 1 time in 1 place than like 30 times in 2 or 3 places you're def not gonna remember to check...

Post

ok guys, i'll see if I can to solve it, and if not, I'll leave the select-case system... however, the script is no so long now; it has turn to 400kb from 1700kb it has when I start this topic. Thanks!

Post Reply

Return to “Instruments”