Dict error message

DaSheng Hen's icon

I use js code to randomly generate 10 numbers and save them in dict. I can receive the numbers normally, but why does dict always prompt "dict: doesn't understand "int"" ?

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

DaSheng Hen's icon

I made a simple thing complicated. In fact, adding bang before dict can eliminate the error.

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

TFL's icon

Is there a reason why you store your random numbers inside of a dict instead of an array or a list, which would be less hassle to handle?

Also, this line `outlet(1, dictName);` won't work because v8.codebox only have one outlet by default (n°0). You need to add outlets = 2; at the beginning of the patch to make outlet n°1 to exist.

The reason why it kept saying "dict: doesn't understand "int"" is because of this line outlet(0, newNum); sending the newly generated int from the codebox left inlet, and [dict] indeed not understanding ints.

Usually when updating a dict from javascript, you just want to output a bang or the name of the updated dict to then trigger further logic in your patch. But to visualize the content of the dict using [dict.view] you actually just need to send a bang once.

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

DaSheng Hen's icon

Thanks for the reminder! The reason for using dict is that I want to visualize the values ​​using dict.view :)

TFL's icon

The reason for using dict is that I want to visualize the values ​​using dict.view

but why, beside learning purposes? So many other, simpler ways to display lists.

For what it's worth, here is how to do the same thing without javascript and without dictionaries, with two possible ways to display the list with its indexes:

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

And another way to build such list with more recent array objects:

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

DaSheng Hen's icon

Wow! This is awesome, these methods are all new to me, I will study them carefully, thank you very much for your help!