Hi, I wonder if it is possible to get the dollarzero value of parent patch from an abstraction in vanilla Pd.
Thanks!
How to get the dollarzero value of parent patch?
Hi, I wonder if it is possible to get the dollarzero value of parent patch from an abstraction in vanilla Pd.
Thanks!
@cuinjune Hi, yes you can create an abstraction with $0 as an argument, which will refer to the $0 of the parent patch and can be invoked inside the abstraction with $1 (or $n, n being the number where you put the $0 argument, for example if you have other arguments first).
Thank you for your answer!
If you don't mind using externals, you can also do this with [iemguts/canvasddollarzero]. The advantage is that you can access $0 without it having to be specified in a creation argument.
there's also [iemlib/parentdollarzero] though it gives the number as a symbol for some reason?
@seb-harmonik-ar in the help patch of [iemguts/canvasdollarzero] one reads that it is a shameless copy of [iemlib/parentdollarzero] which I'm not what it means.
Also [iemguts/canvasdollarzero] outputs a symbol which seemed strange to me as well, but then this value is usually used for names of arrays and [s ]/[r ] pairs, which is set via symbols.
Just an observation from patching for about 10 years now: if your system relies on common $0 values, the convenience of abstractions needs to be weighed with the inconvenience of having to pass it down as a parameter.
It might be useful, especially if you need to incorporate it into abstractions that already have a lot of established parameters (so that adding $0 to them would make things icky) to create a central source for $0 in your patch to which you could send a [bang( and receive $0 back.
Thanks for all the great suggestions.
I decided to take the below approach inspired by @Zygomorph's solution.
Here's another solution I found using 1 global variable and fewer objects.
Here's another hacky solution which uses no global variable.
@cuinjune There are ingenious solutions but what do you need the $0 for? For me most of the time is to be able to use sends, receives and tables from the parent patch inside the abstractions. How can I use the float you get in send, receives, tabreads etc? To me using arguments sounds more practical most of the time for this very reason.
@weightless I agree.......
No variable....... global.
Variable............ patch >abstraction local.
$0..................... abstraction /sub-patch local.
The reasons for use of $0 is to have an exclusive local variable and not pass it "down" or "up".
More or less.
Except where the same "mother" patch might be opened many times, without forethought that it might ever be treated as an abstraction.
But using a global transfer of $0 would be a big undertaking for every patch, with only a rare benefit. I would guess it would be more efficient to rewrite a patch when such a problem is encountered.
And the main (only?) benefit would be to send/receive pairs, which without dynamic addressing available cannot benefit unless the $0 value is sent to an abstraction as an argument in the first place.
David.
@weightless I mostly use $0 to communicate with the parent patch as well.
And I understand your point that it is much easier to use it in abstractions when $0 is passed as an argument.
But in some cases, I think it is a bit inconvenient having to write $0 argument whenever I create the abstraction.
So I was wondering if there was any similar solution like [iemguts/canvasddollarzero] in vanilla Pd. I personally think something like it can fit better for some users design-wise.
And here's an example of how you can use the float $0 in send, receive, and tabread.
I know it is not very clean way to receive. but sending values and reading arrays isn't too difficult.
@cuinjune I get your point too, and it's interesting to know that you can do it in vanilla. Thanks for sharing it.
Perhaps, like you said, it's down to one's style of coding. For now I personally just know that if I make an abstraction that requires to access objects from upstream, the parent $0 is always the first argument, and trade this inconvenience for readability. But if I ever should need it, I'll keep in mind your method.
@cuinjune interesting, but i don't get the point.
If i open your root patch twice, it will break the separation, because abstractions inside the first and the second root patch will all communicate with the same instance of root patch. In your first example with the second instance, in the second example with the first instance.
If you don't open root patch twice, you don't need $0 at all and can just use [table root-array] and access this directly.
What am i missing?
Also note that instead of passing $0 through creation argument, you can just use inlets and outlets for perfect separation.
@cuinjune on a second thought i think it is possible to expand your counting up example to actually get separation. This would require that the abstractions inside the second instance of root patch start counting not at 1000 but ask first if there is a previous count number and start from there (+ 1). This way they will get the answer only from the second root patch.
Ok, this should work:
@cuinjune i just saw that you did a similar thing in your first example. Sorry, i missed that, i should read more carefully. Please disregard my previous posts, sorry for the confusion.
@ingox No worries man.
I just created my draft as an abstraction.
Please see the post below if anyone is interested.
Thanks! [POST DELETED]
https://forum.pdpatchrepo.info/topic/10866/getdollarzero-vanilla-abstraction-to-get-0-from-any-canvas
@cuinjune Great, but they are still not separated. Open root twice and you see. This can be prevented with a spigot like you did above.
@ingox You're right. I tried to avoid using global variable name if possible. now I understand that it can be a problem in some cases.
I just deleted my post. Thank you for pointing it out
Oops! Looks like something went wrong!