Hi,
i'm working on an abstraction with data structures inside (franks tutorial was very helpful http://puredata.info/community/projects/convention04/lectures/tk-barknecht/t... ) and i use $1 in the name of the template (like this: struct $1-template float y array numbers $1-template-num), this works and i have a workaround for getting both - a non changing part in the data structure which is quite unique for each instance of the abstracion ( ;) i just have to take care not to give two abstractions the same creation argument). g.
ps.: in the tutorial by Gregorio Garcia Karman is also a good starting point ( http://puredata.info/Members/ggkarman/Tutoriales/datastruct_en_02/view )
Frank Barknecht schrieb:
Hallo, Mike McGonagle hat gesagt: // Mike McGonagle wrote:
I think this should be allowed, hell, even the use of other $ arguments. It would be nice to be able to allow abstractions to create their own private data structures, or at least ones that could be named based on a creation argument.
All this *is* allowed. But Luke's problem is more general: If you use $0, its value is only valid in a running patch. This not only affects data structures, but everything, i.e. also qlist, textfile and so on.
If you write the value of $0 into textfile, you get something like 1023, which probably is not the same value $0 has when you reload the file later in a different context.
It all boils down to the fact, that Pd only has global scoping and that using $0 is just a limited workaround, but not adding a real local scope.
The only thing that could be considered local scope in Pd are direct patch cord connections: They are as local as it gets. So what I generally do if I use $0-structs is to not save the data structure instances with "write pd-x" but traverse and parse them down into [textfile] and use that for storing and reloading. I.e. with [struct $0-a float x float y]
and a data subpatch [pd x], I'd use traverse pd-x, and write each x,y-pair into [textfile]. Then to reload, I clear pd-x, and dump the textfile's contents to an [append $0-a x y].
This acctually has the advantage, that I can prepare the textfile in a text editor or so.
Ciao