Can Anyone Explain This Array Behavior?
Posted: 19 Aug 2015 00:59
I was trying to match an incoming sysex substring, but I've trimmed this down to the bare essentials to demonstrate the problem & the template below is dirt-simple.
Objective: To compare a subarray to another array
Problem: Getting a "match" on certain arrays with different contents
I'm certain I'm doing this wrong, otherwise it would be all over this board. If there is a better/simpler way to compare arrays, I sure am ready for it
How it works:
Three buttons, three monitors.
The buttons load Array1 with three different 13-byte strings.
CompareArrays() script executes on expression Array1 (whenever it's changed by a button)
it grabs a subarray and compares it to the same fixed 6-byte array in each case,
The three monitors display the substring from Array1, the fixed array, and a 1 for match, 0 for no match.
Case 1 should match, and it does.
Case 2 should NOT match, but it does.
Case 3 should NOT match, and it doesn't
At the limit of my talent trying to understand why.
Here's the main compare script:
//Array1 is loaded in the buttons
decl SubArray1 = subarray(Array1,7,6); // grab a substring to compare
SubArray_1.value = arrayToHex(SubArray1); //display substring in hex in monitor
decl CompareArray = {0x00, 0x00, 0x15, 0x00, 0x2C, 0x5F}; //here's our string to compare
Compare_Array.value = arrayToHex(CompareArray); //display the compare string in hex in monitor
if (! sumof(CompareArray - SubArray1) ) Match.value = 1; //compare the arrays
// if they match, display 1, otherwise display 0
else Match.value = 0;
**************************************
Objective: To compare a subarray to another array
Problem: Getting a "match" on certain arrays with different contents
I'm certain I'm doing this wrong, otherwise it would be all over this board. If there is a better/simpler way to compare arrays, I sure am ready for it
How it works:
Three buttons, three monitors.
The buttons load Array1 with three different 13-byte strings.
CompareArrays() script executes on expression Array1 (whenever it's changed by a button)
it grabs a subarray and compares it to the same fixed 6-byte array in each case,
The three monitors display the substring from Array1, the fixed array, and a 1 for match, 0 for no match.
Case 1 should match, and it does.
Case 2 should NOT match, but it does.
Case 3 should NOT match, and it doesn't
At the limit of my talent trying to understand why.
Here's the main compare script:
//Array1 is loaded in the buttons
decl SubArray1 = subarray(Array1,7,6); // grab a substring to compare
SubArray_1.value = arrayToHex(SubArray1); //display substring in hex in monitor
decl CompareArray = {0x00, 0x00, 0x15, 0x00, 0x2C, 0x5F}; //here's our string to compare
Compare_Array.value = arrayToHex(CompareArray); //display the compare string in hex in monitor
if (! sumof(CompareArray - SubArray1) ) Match.value = 1; //compare the arrays
// if they match, display 1, otherwise display 0
else Match.value = 0;
**************************************