Can't set array of single string into a dict

alain's icon

Hello,

I am banging my head against something that seems rather simple but as I am not familiar with the dict series of objects I can't seem to figure out how to make it work.

I basically want to set an array in a dict as a single text string, rather than a list of strings. Is it possible ? Would someone be kind enough to show me how ? Attached is an example of what i mean

Thanks

Alain

Max Patch
Copy patch and select New From Clipboard in Max.

TFL's icon

My first thought to convert a string to an array is using [string.toarray], but given your string is already a list and not a single symbol, sending it into a dict.pack makes it an array automatically

Max Patch
Copy patch and select New From Clipboard in Max.

alain's icon

Hi TFL,

Thanks for the comment and patch, unfortunately, in the example I send there is a mistake.

I need one sole string in the array, sorry, here is the corrected patch showing what I am looking for,

Max Patch
Copy patch and select New From Clipboard in Max.

Source Audio's icon

replace sprintf with message

see the difference

TFL's icon

something like this then


alain's icon

Hey thank you TFL, this is exactly what I needed !

I looked into the array object, but did not understand how to make it work. So thanks for that.

TFL's icon

Basically all array.* objects convert non-array messages into an array. That array will have N elements if the input message is a list of N items, or 1 element if it's a single symbol, float or int. Then the object will perform the operation it is meant for (.push, .concat, .filter.....)

[array] just stores what arrives into it, so it will makes whatever it receives an array, and send it as is (and keep it in memory until it receives another message)

If you send it an array, that array will remains as is, it won't be wrapped as a sub array. For that, use [array.wrap]

alain's icon

Thanks again for your time TFL for making things clearer. People like you make this forum a great place :).