Home > Enterprise >  How to write to arrays using loops in PureData?
How to write to arrays using loops in PureData?

Time:11-12

I'm writing random numbers in an array using loops in PureData. For some reason in loop one Pure Data starts wrting from index 1 instead of 0 and finishes on index 0 after the loop, this is not what I want. In loop two I found a solution using an extra f and bang, PureData does the expected, starting from index 0. In both cases console prints the data in the same order (numbers are random, the order is the same), just the graph, reflecting the array, is different.

Does anyone know why the first case fails and the second works? My guess its something related to the flow of data into the left and right inlets of tabwrite.

loop one

Code

Code

Console

Console

Graph (1.151 is on index 1 instead of index 0)

Graph (1.151 is on index 1 instead of index 0)

loop two

Code

Code

Console

Console

Graph (1.742 is correcly on index 0)

Graph (1.742 is correcly on index 0)

CodePudding user response:

Message order. You have a fanning output on the [f] object. Use a trigger [t b f] (short for [trigger bang float]) to make the order explicit. If you see an atom with multiple connections on one output, that's a red flag! Always use trigger objects, because without them the order in which you made the connections will be the order in which the messages will be sent. That's not visible in the patch, so it should be avoided!

Read patch with trigger

There is another issue in your patch. Consider this case: If NotasPor0it is 8 and the counter is at 6, then NotasPor0it is changed to 4, the select object [sel] will never trigger the reset function of the counter idiom and continue to count...

  • Related