Identifying the position in an array

khashara's icon

Hi all,

I'm receiving an OSC message as an array that has 16 positions. Each position is a random number. I want to identify the position in the array rather than just the number it is receiving. I have used the zl object to get the length of the array but I can't figure out how to get the position as an integer.

Any help would be appreciated.

Markus

Pedro Santos's icon

Isn't the position inherent to the order of the elements in the list?
If you want to obtain the value of a specific element in the list, you can use the zl.nth or zl.lookup.

khashara's icon

Thanks Pedro. The zl.nth will output the actual value received (the random number) from the OSC message. Instead of the random number I want the position number. For example, say you have a grid of 16 squares in Processing and when you click on say the forth square it generates a random number that is sent to Max. Instead of knowing the random value, I want to know square number 4 is triggered. Hence an integer value of 4.

I hope that clarifies what I am asking.

Cheers,

Markus

Pedro Santos's icon

So what you really want is to compare the received list to the previous one and output the index of the changed element(s). zl.compare will do that.

Max Patch
Copy patch and select New From Clipboard in Max.


khashara's icon

Thanks for the speedy reply Pedro! I used the unpack object and added a condition to produce the integer value. And it seems to solve my problem. I will definitely try out your patch and see if it does the trick as well.

Cheers,

Markus