Variable Roll Value for Audio Rate Sequencer

Here is an audio rate sequencer i am in the process of completing. I’ve been struggling with getting the sequencer to give rolls of a variable length. Here is how I am trying to do it:

Each step has a number of "spaces" – these are the total number of samples in a given step. Roll values can be any even divisor of the total number of spaces, excluding one. So, for example, if a step has 12 samples in it, the roll can be of values 1, 2, 3, 4 or 6.

The reason is you have to have a 0 following each 1 in order for it to be a click, and thus trigger the sample to play (using zigzag~ connected to wave~). The number of zeros following a 1 depends on the roll value. For example, with 12 spaces, a roll value of 6 means 1 zero for each one, 4 means 2 zeros for each one, 3 means 3 zeros for each one, etc.

Though this seems straightforward, my patch is not working and I have absolutely no idea why. The part in the big pink box is where my problem lies. I would deeply appreciate any help. This has been a bewildering and frustrating experience. Thanks for your time.

– Pasted Max Patch, click to expand. –

Copy all of the following text. Then, in Max, select New From Clipboard.

if anyone is interested, i came to a brief and simple solution through javascripting (was my first time using the js object. i was surprised at how amazingly easy it was to incorporate some line code for processes that can get rather convoluted with strictly max objects).