[select] input types and broken "for" loops

asciishallreceive's icon

select-bug.maxpat
Max Patch

Here is a simple counter-style "for" loop, a very common code block for metronomes and algorithms. I use these all the time. Here is a bizarre mismatch in behavior between two designs of the same code block. The only difference is in input types sent to [select].

Version 1 (left side): the for loop sends the output of [int] to a [number] object before going to [send]. Works as expected, bangs the [3] message, resets the counter and continues to countdown from 3 to 0 repeatedly.

Version 2 (right side): the output of [int] goes directly to [select]. It doesn't work, but the way it fails makes no sense. Pay attention to the order of operations in the console.

  • I start the metro (toggle on), having manually pressed on the [3] message before starting the loop. (first two printouts — bang3 bang, start 1)

  • It counts down from 3 to 1. (next three printouts, — int 3, int 2, into 1)

  • The print order shows that [select] reads a 0 before it actually appears in the output of the [int], presumably loading a 0 into the int, so that the next time int receives a bang it should "reset," and output a zero. Instead, it goes negative in this version of the patch.

Why would these outputs be different simply because the number is between the int and select objects?

schlam's icon

Dif you tried to use [trigger] after your [i] to choose in wich order its 3 outlet patch cords are triggered ?

asciishallreceive's icon

Hi Schlam. Thanks, I just tried that out, but it doesn't fix the weird behavior. Just one of the three outlet cords is influencing the patch, and the other two are simply displays of the current output. What's weird is that the version on the left should work the exact same way. Logically these are equivalent ways of making the same patch, but for some weird reason, it only works with a [number] box in the middle.

Wil's icon

Other testing shows this to be true

[i] seems to need helper

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

mizu's icon

move sel 0 to the left under - 1 . Or a t i i i after i : in wich order Max visual trigs, right to left, bottom to top :-)

mz

Wil's icon

indeed