Kontakt - variable in an array

Sampler and Sampling discussion (techniques, tips and tricks, etc.)
Post Reply New Topic
RELATED
PRODUCTS

Post

If I want to reference one of two arrays named %array1 and %array2, how can I do that using a variable?

For example if $myVariable = 1, how would I reference the first entry of %array1 using that variable in the array name? In other languages this might be something like ("%array"+$myVariable)[0] or %array.$myVariable[0]

Post

%array[0] references the first entry in that array. If you want to assign that to your variable, then, of course, $myVar := %array[0]. Or, if you want to assign your variable to the first entry in the array, of course, %array[0] := $myVar.

Post

Thanks very much but that's not what I meant. Let me explain it better with with an example:
I have an array called %ItemsInHouseNumber1 which contains "fridge", "sofa", "broom".
So for this array %ItemsInHouseNumber1[0] = "fridge"

I have another array %ItemsInHouseNumber2 which contains "freezer", "oven", "bucket".
So for this array %ItemsInHouseNumber2[0] = "freezer"

Now I generate a random number 1 or 2 and store that in a variable named $arrayToReference

I want to call the first entry of either the first array or the second array depending on what value $arrayToReference is at that time. So the array name must contain the variable - something like %ItemsInHouseNumber+$arrayToReference[0] would give me the first entry in one of my arrays depending on what value $arrayToReference has at that time.

Post

If I had titled the thread "Variable inside the name of an array" maybe it would have been clearer.

Post

holmesAt5 wrote: Fri Feb 26, 2021 4:15 pm ... So the array name must contain the variable - something like %ItemsInHouseNumber+$arrayToReference[0] would give me the first entry in one of my arrays depending on what value $arrayToReference has at that time.
Mmmh, I guess what you want is: The array(-name) itself should be a variable
again. That is possible in most languages, but I don't know if it is possible for
kontakt-scripting.
free mp3s + info: andy-enroe.de songs + weird stuff: enroe.de

Post

This is not possible in KSP directly. But you could probably work around it by using a 2D array if you use SublimeKSP compiler along with Sublime Text 3. Basically, have both those arrays merged into one array where you access a different "array" by changing the vertical index.

Post

I'll look into that. Thanks. I'm trying to get Kontakt to access note values stored in arrays. There is one array for each musical scale. There are hundreds of scale arrays so doing this via "if the user chooses array 01 go to %array01, if the user chooses array 02 go to %array02" seems like a ridiculously impractical way of working.

Post

Yes, definitely impractical, and a 2D array is the solution. If you take a look at some factory scripts (i.e. Constrain to Scale), you can see it's done exactly the same way - all scales in one array only.

Post Reply

Return to “Samplers, Sampling & Sample Libraries”