Search code examples
parametersargumentspuredata

How to pass creation arguments to a abstraction?


Question regarding Pure Data: do abstractions support creation arguments? If so how can I make them work? I have a setup like this and I would expect 1 to appear in a bottom number box in bar.pd. Do I really have to pass all arguments to foo using other boxes (as shown in bar2.pd)?

foo.pd:

[inlet]
|
[outlet]

bar.pd (does not work):

[foo 1]
|
[0\

bar2.pd (this works):

[loadbang]
|
[1(
|
[foo]
|
[1\

Solution

  • To answer your question immediately: yes. Subpatches, or to be more precise abstractions, support how many creation arguments as you wish.

    You can refer at the creation arguments inside the abstraction as $1, $2, etc... but be careful because these kinds of variables are NOT the same as the ones used in messages.

    So if foo.pd is:

    [loadbang]
    |
    [f $1]
    |
    [outlet]
    

    And you call it from bar.pd in this way:

    [foo 1]
    |
    [1\
    

    The result coming out of the foo outlet will be whatever variable you will chose to insert as creation variable when calling foo.

    To conclude, no you don't have to pass all arguments to foo using other boxes.