[PD] $-Dollar sign variables instantiation

Frank Barknecht fbar at footils.org
Wed Jul 19 19:11:32 CEST 2006


Hallo Brien,
briencrean at eircom.net hat gesagt: // briencrean at eircom.net wrote:

> I have attached a simple patch below in txt format. I dont
> understand why when using the 'symbol' object I can instantiate the
> $1 variable to a string and when I try the same with the $2 variable
> it says "error: $2: argument number out of range".

You've run into one of the issues in Pd that is most difficult to
understand for beginning Pd users (the other is execution order, which
you will probably run into next week. ;) 

The culprit is the funky way, Pd messages are constructed. I would
recommend to read http://puredata.info/dev/PdMessages for an
introduction. Basically it's this: Pd messages consist of two parts,
the so called "selector" and the "data" following it. The selector tells
Pd what kind ob data it should expect. Typical selectors are "symbol"
"float" and "list". A complete symbol-message then looks like this:
"symbol WORD". Sometimes the selector is implicit and can be omitted.
"float 3" is the same as "3" because of this. However the
"symbol"-selector never can be omitted: "symbol WORD" is something
different from "WORD". The latter is a "WORD"-message, but no
"symbol"-message anymore. (Those kinds of messages sometimes are
called "meta-messages". The [read -resize somefile.wav( message of
soundfiler is an example: It's a "read"-meta-message.)

Now comes the tricky part: In dollar expansion, the selector is
ignored. $1 starts counting at the first element of the data-part of a
message. So if you have a message [$1( and send it a [symbol WORD(
message, it will result in "WORD", however if you send just "WORD" it
will give you a: "error: $1: argument number out of range" warning.

> My hope is to use the $1 and $2 as part of a message for a read
> message for the 'soundfiler' object so that I can read multiple
> sound files into multiple tables using a text file (which will
> contain the sound file names and table name).

You can do two things here: Either store stuff with the proper
selector like "symbol filename.wav;" in your [textfile] or use another
common trick: [list] is a fabulous object to convert everything to
proper Pd messages. Just put a [list] in from of your [open $1(
message and all will be fine and dandy.

For example if you send [WORD( into [list] out comes a "symbol WORD"
message just as you want for your [read $1( message box.

Ciao
-- 
 Frank Barknecht                 _ ______footils.org_ __goto10.org__




More information about the Pd-list mailing list