Possible BUG in JS and DICT operations
Dear users,
I have experienced what is probably a BUG in DICT and JS because the result are somewhat contradictory.
I can access a dictionary and show/parse its contents (in the example patch you can click on "accessMainDict" message and see the results in MAX window)
I can create a new dictionary and store some arbitrary data (in the example patch you can click on "createNewAndSet " message and see the results inside the [dict oriundo2] object)
what i have problem is creating a new dictionary and COPY some data from another dictionary. In the example patch if you click "createNewAndCopy" the script will make a new dictionary and copy some data in it. In the same routine it will print the keys and the values of the new made dictionary. but if you click on the dictionary the copy hasn't been made at all.
Can you please give some help on this?
Thanks,
Alessandro
some times i see that the embed of the MAIN dict is not working. here is the text to be copied
{
"level1A" : {
"level2A" : {
"level3A" : {
"key1A" : [ "value1A", "value2A" ],
"key2A" : [ "value3A", "value4A" ]
}
,
"level3B" : {
"key1B" : [ "value1B", "value2B" ],
"key2B" : [ "value3B", "value4B" ]
}
}
}
}
Hi !
u cant assign dictionary to dictionary with assignment operator . you need to clone retrieved instance . As every GET key returns value or Dictionary .
so instead of ... assigning
subDictionary = level3B;
you need to clone it
subDictionary.clone(level3B.name);
ive checked it ,and its working
You are as always very kind and competent. I just have this question: How do you know that? The documentation for JS in max is pretty non-existent. Can you point me or suggest some link, documents or other info on how to have a complete overview of dictionary operations in javascript for MAX?
Thanks!
Hello !
thank you . Unfortunately i do not know about any additional documentation than written by Cycling team . Also check JS tab in Dict help .
I think API is mirrored from MAX to JS for our use (at least wider part).
But the truth is that the "cloning" habit ive met in C external development , where things are more "strict" (require different coding attitude) than lose typing as in JS (which i love JS for it by the way) . Both worlds helps a lot , ive also read somewhere here that is a good practice . but time consuming , sure .
Ratox ! u can always ask here if you are "struggled" ... i will try to provide help if i know how . or private way.
# EDIT :
also , when you use Dict in JS that is instantiated in MAX directly , you dont need to use "new" operator on every function call . "new" should be used if you are instantiating new Dict from within JS only (i didnt met any issues but it seems to be a good practice). But then you are responsible to free memory with "freepeer()" function called on your instance ;
so you can assign instance to variable
var d = Dict("name");
and free it later
if(d instanceof Dict) d.freepeer();
maybe it would work instead of "clone" for your retrieved instance of subdictinary keys ? i cant check it at the moment . im just guessing .
If you will be willing to check it out , please let me know if its working .
Thank you very much! You are absolutely helpful!
But i don;t understand exactly what you mean here:
...
maybe it would work instead of “clone” for your retrieved instance of subdictinary keys ?
...
if you find time to explain this aspect it would be helpful to me and to everybody involved in similar questions...
thanks again,
Alessandro
I can send a value from max objects environment to a global object in a script but how can i do the opposite? how can i retrieve a value to send to an object?
i mean:
if in a script i have:
var processIdentifier = Global ("process_id");
i can send some value from a max message like [; process_id storedvalue $1]
but i cannot create a
[r process_id] object to receive any value assigned in a script, i get this error when i attempt to create the [receive] object:
...process_id: already exists.