Hi, I have learning about PD for a little while now and gone through quite few tutorials but there's something I can't figure out. In BASIC you can say If x = 1 then z + 10 , If x = 2 then z - 10.
How would I go about doing that in pd?
Newbie question about variables
Hi, I have learning about PD for a little while now and gone through quite few tutorials but there's something I can't figure out. In BASIC you can say If x = 1 then z + 10 , If x = 2 then z - 10.
How would I go about doing that in pd?
That turns out to be one of the most difficult questions to answer in Pd.
Technically you can use the [value]
object along with the [expr]
object to do this. But typically Pd users will just feed a copy of the "z" value further down the patch and store it in a [float]
to be output and added to the appropriate number (in this case either 10 or -10).
When there are many variables to keep track of users will sometimes use dollarsign arguments to handle the data. But this has its own readability problems because it typically (at least) doubles the amount of information you have to track in your head-- i.e., mapping simple variable names to variable positions.
It would be nice to be able to send objects through the wires which contain key/value pairs, but that would bring its own problems.
Just remembered-- here's a pattern Frank Barknecht posted to the user list some time ago:
Here we route based on the value of "x". The [route]
object chops off the 'x' value, which leaves us with "z" for the output. Then it's just a matter of adding the desired value to z.
This works well for two (or maybe three) variables-- that is, as long as it's easy to remember the position of "x" and "y" in the list output from "pack". For more complex conditions you can throw an [expr]
in between the "x" and the "route".
i more often use the [select] object for if cases. if-so-select.pd
EDIT: corrected spelling mistakes in pd file
@Johnny-Mauser said:
i more often use the [select] object for if cases. if-so-select.pd
That can work, too. But you need to remove the space between the sign and the number in those message boxes.
@jancsika Oops my bad! I will correct the file for further record..
Oops! Looks like something went wrong!