dict replace: hierarchy syntax

rklem's icon

Hi everyone,

here I am with another dict question:

"replace sound_1:: volume 0"
""replace sound_1:: filter 0"

...creates two sub categories in a dict. Is it not possible to combine both in one message?
I tried all kinds of combinations, but nothing worked yet.

I assume the issue here is that I'm using "replace" to build a basic hierarchic dict structure, but it's probably not meant for that. If so, what's the right approach to do so: Just create it in the Dictionary Editor? I did that now, but I'm wondering if there are better/other ways.

Thanks a lot!

Source Audio's icon

"replace sound_1:: volume 0"
"replace sound_1:: filter 0"

...creates two sub categories in a dict.

no it does not, only one of them survives - the last sent.
maybe you have inserted space between :: volume and :: filter
by mistake ?

to do what you asked for - create or set that 2 items,
you can send this message:

replace sound_1::volume 0, replace sound_1::filter 0

rklem's icon

Thanks – and sorry, I wasn't clear enough. Your message works, but it's just the standard way of combining messages with a comma. I thought there might be a way to create the two sub categories without repeating the entire path (= without repeating "sound_1"). But I guess that's just not possible.

On combining "replace sound_1:: volume 0" and "replace sound_1:: filter 0" as two separate messages: I'm not sure what you mean. This works, and both survive, not only the last sent.

Source Audio's icon

blue is your original message
only last one survives, because of spaces.
red is proper message, without spaces.
If that is not the case in your max version,
it would be interesting if you post which one it is.

read help files for dict objects like deserialise, pack, group etc.

can give you few ideas for your needs.

or use sprintf, zl.iter and other objects to form replace
messages

rklem's icon

Thanks again, and sorry for my oversight. You're absolutely right. I just missed the point about spaces after "::". Could you explain what a space after "::" means in terms of hierarchy?

And thanks for your suggestions. I read help files for most of the dict objects already – and I regularly use sprintf (life saver), but I'll add zl.iter to my to do list.

tyler mazaika's icon

:: indicates a parent-child relationship of keys. More specifically it means that the parent key's VALUE is itself a dictionary (as opposed to a number, symbol, or list). You can nest dictionaries inside dictionaries inside dictionaries this way and access them like:

parentkey::childkey::grandchildkey etc.

If you want to do less work putting together the symbol for setting/getting values, you can also use a dictionary reference with the "replace" message like this:

As you can see this also makes it easy to define a lot of different "sound_X" later with simpler/fewer messages (since you just update the left side inlet of [join] with the next sound_X).

This works more easily to create nested structures (like the "subdict" key used here) and it's easier to add/change/remove the properties you define for each sound_X (e.g. volume, filter) later because the messages to the [dict] object don't need to change to reflect your change in structure. The message is always just "replace <sound_X> dictionary <uWhatever>".

rklem's icon

This helps a lot. Thank you so much!