Kontakt - variable in an array
-
- KVRer
- Topic Starter
- 10 posts since 2 Feb, 2021
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]
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]
- KVRAF
- 23102 posts since 7 Jan, 2009 from Croatia
%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.
-
- KVRer
- Topic Starter
- 10 posts since 2 Feb, 2021
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.
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.
-
- KVRAF
- 2590 posts since 19 Mar, 2008 from germany
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
- KVRAF
- 23102 posts since 7 Jan, 2009 from Croatia
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.
-
- KVRer
- Topic Starter
- 10 posts since 2 Feb, 2021
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.
- KVRAF
- 23102 posts since 7 Jan, 2009 from Croatia
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.