Append value to a dictionary's array item for a key? (VEX)

   2838   4   0
User Avatar
Member
103 posts
Joined: Nov. 2019
Offline
Hello!

I am running into this issue. Given a dictionary that has an array as one of the items, I am not finding the way to append a value to the array inside the ditionary. I might be missing something. Is this possible?

Thanks!
Edited by Cicuta - Dec. 31, 2023 20:14:23
User Avatar
Member
9380 posts
Joined: July 2007
Offline
it is definitely possible, but rather than us guessing whether you are dealing with Python or dictionaries in VEX or dictionary attributes and giving you random examples, it's better if you clarify your exact issue you are running into

but in short in VEX:
//if myDict contains: {"key": [1, 2]}
append(myDict["key"], 3);
//results in: {"key": [1, 2, 3]}

in Python:
#if myDict contains: {"key": [1, 2]}
myDict["key"].append(3)
#results in: {"key": [1, 2, 3]}
Edited by tamte - Dec. 31, 2023 15:42:40
Tomas Slancik
CG Supervisor
Framestore, NY
User Avatar
Member
103 posts
Joined: Nov. 2019
Offline
True indeed. Sorry about not specifying! I was talking about vex! I thought I had tried your suggestion, I will check where my mistake is.
Thanks Tomas!
User Avatar
Member
103 posts
Joined: Nov. 2019
Offline
Hello again!

tamte
but in short in VEX:
//if myDict contains: {"key": [1, 2]}
append(myDict["key"], 3);
//results in: {"key": [1, 2, 3]}

While this is indeed working for integers and floats, it is not working if the array for that key is a string array. It is giving me the following error:

Invalid source /obj/hashmaps_dictionaries/anagram_list_hashmaps/attribvop1.
(Error: Ambiguous call to function append(). Candidates are: void append(string &; string), void append(string &; string) (56,1:6)).


Is there a workaround or something that I am missing?

(It also seems like vector arrays aren't supported either, upon testing I am having the same issue reported here: https://www.sidefx.com/forum/topic/81985/)

Thanks!
Edited by Cicuta - Dec. 31, 2023 20:30:56
User Avatar
Member
9380 posts
Joined: July 2007
Offline
Cicuta
if the array for that key is a string array. It is giving me the following error:
while append() seems to have this issue push seems to work so you can potentially use that:
//given myDict contains: {"key": ["1", "2"]}
push(myDict["key"], "3");
//results in: {"key": ["1", "2", "3"]}

Cicuta
(It also seems like vector arrays aren't supported either, upon testing I am having the same issue reported here:
the docs don't list vector arrays in the list of supported dictionary values so it's likely they may not be supported
you can potentially use serialize() unserialize() functions to convert between flat float array and vector or matrix arrays, therefore store them as flat float array in dictionaries
Edited by tamte - Dec. 31, 2023 22:52:07
Tomas Slancik
CG Supervisor
Framestore, NY
  • Quick Links