Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision | Next revisionBoth sides next revision | ||
mozaic_tips_and_tricks [2020/01/12 20:46] – Added 'Store two positive values into a single combined variable' _ki | mozaic_tips_and_tricks [2020/01/12 21:09] – Added two and multi dimensional array acces _ki | ||
---|---|---|---|
Line 8: | Line 8: | ||
* [[mozaic_tips_and_tricks# | * [[mozaic_tips_and_tricks# | ||
* [[mozaic_tips_and_tricks# | * [[mozaic_tips_and_tricks# | ||
+ | |||
+ | ===== Two dimensional Arrays ===== | ||
+ | < | ||
+ | Each variable in Mozaic is in fact an array with a maximum of 1024 elements. Scripting often needs two dimensional arrays, but the variables only offer one dimensional access. | ||
+ | |||
+ | Its is very easy to ' | ||
+ | |||
+ | < | ||
+ | xMax = 16 | ||
+ | |||
+ | x = 2 | ||
+ | y = 5 | ||
+ | value = 42 | ||
+ | |||
+ | // write the value to position x,y : | ||
+ | twoDimStorage[ x + xMax *y] = value | ||
+ | </ | ||
+ | |||
+ | Retrieval of values is done using the same folding: | ||
+ | < | ||
+ | // retrieve value from 5,3 | ||
+ | x = 5 | ||
+ | y = 3 | ||
+ | value = | ||
+ | </ | ||
+ | |||
+ | Mozaics array length is limited to 1024, so 32x32 just fits - but 128x16 (often needed in midi programming) doesn‘t. | ||
+ | |||
+ | \\ | ||
+ | |||
+ | There is a single two dimensional array in Mozaic that fits this dimensions, the note state array. Since it is special, there are separate functions: | ||
+ | < | ||
+ | ResetNoteState initValue | ||
+ | | ||
+ | SetNoteState row, column, value // Sets a value | ||
+ | value = GetNoteState row, colum // Retrieves the value | ||
+ | </ | ||
+ | There is only one array of this kind, but sometimes you Need to store multiple values. In such a case, its possible to fold these values into a single value - see the tricks below: | ||
+ | |||
+ | \\ | ||
+ | |||
+ | |||
+ | ===== Multi dimensional Arrays ===== | ||
+ | < | ||
+ | |||
+ | The above folding can be expanded to multiple dimension, here an example for a 3 dimensional array folded into one dimensions: | ||
+ | < | ||
+ | array[x + xMax * y + xMax*yMax *z] = value | ||
+ | </ | ||
+ | |||
+ | Since Mozaic arrays are limited to 1024 elements, xMax * yMax * zMax needs to be less or equal 1024. | ||
+ | \\ | ||
===== Store two positive values into a single Variable ===== | ===== Store two positive values into a single Variable ===== |