sorting

toddwelti's icon

I'm working on an patch which involves some sorting. I need to sort lines in a small data table according to values in one column. The only way i can figure to do it is using the coll object. I don't know if I am losing my mind or what but it seems like it is working one minute and not the next. i am tring to use "sort 1 2" to sort using the second column of data:
1, 1 14 500;
2, 2 16 400;
3, 3 9 300;

I thought it was working at one point, but not now, no how. I cannot seem to get what i expected:

2, 2 16 400;
1, 1 14 500;
3, 3 9 300;

It seems there is a lack of simple sorting mechanisms for tables (not single lines of data such as in a message) in Max. i have looked around and can't find any other way to do this other than coll. Do i have to write my own external? I have done it for PD, but it's been a while...

toddwelti's icon

OK, no one will probably believe this, but I have two coll objects and have been trying (for hours) to get one to sort using second of three columns, and the other to sort using the thrid of three columns. For HOURS, I could only get one or the other to work, never both. Through trial and error i have found that using
"sort 2 1" message works for the second column and
"sort 1 3" message works for the third column.

I was expecting "sort 1 2" and "sort 1 3" or "sort 2 1" and "sort 3 1". It seems the order of the sort column in the message sent to coll is reversed on one case - and yet that is the only way it works. Can someone put me out of my misery, or tell me I'm crazy or explain this? Is this a known bug? i can find anything on it anywhere.

realshafer's icon

Check out the example patch here. The first value (x) in the message "sort x y" determines the type of sorting, ascending or descending. The second value (y) determines which column you're using for the sorting. Hope this helps.

collsorting.maxpat
Max Patch
toddwelti's icon

Thanks, where did that example come from? i wish i had it earlier! I must have tried every combination of using first or second number to be the column (the documentation isn't clear on this), and using 1-based or 0-based referencing but somehow missed the correct combination.

metamax's icon

The first element is not the first element. It's the zeroth element.

You see, to make it more exciting and interesting for new users, you will hear most people in these parts use the term "first" used to describe either 0 or 1 depending on the numbering system. This one little issue has easily caused me HOURS of stress and frustration debugging patches. But I could say the same about a good puzzle or game - so I don't complain.

Roman Thilenius's icon

dont worry meta, most of us once started using max because we thought it is a tool or a solution only to find out that in fact it is a neverending puzzle in public beta status.

but since i use it since more than ten years now i can hardly claim that this would be a disadvantage.

metamax's icon

Indeed! A betaphysical quandary to be sure.

metamax's icon

Ultra High Grade.