I have a Map variable: the Key is a simple string and the Value is a structure.
The structure is made by another but set to an array containing two integers. Images for better understanding:
What I want to do is to add multiple Values to a Key at runtime. For example, I did it on the image:
yes… We are sure that you can only add unique keys to a Map or Set.
If you want to add multiple values to the same keys, you need to use an array or struct as value… Which variables are both predefined.
You could add multiple values inside a struct, that sits inside a key… Yes…
Like
{“Key”, Struct{int, string, name…}}
But not
{“Key”, int, string, name…}
Or
{“KeyA”, int}
{“KeyA”, string}
And that’s not a restriction of the Engine… But of the Cpp api
Yes, that part is clear to me that duplications are not allowed.
Is the predefined simple means what I wrote before that I can set them manually but can’t change/add/remove them runtime? Or that I must set the var types like int, string, etc.
I assume that should look something like this, except I have two ints inside the struct:
Reflecting on the last image from my original post, which would look like this, I guess:
{“Key”, Struct{Struct{int, int}}}
There is only one Value/Key but there are more elements inside a Value, which is what I really wanted to ask and what I want to do: add and remove elements at runtime. Unlike how I wrote in my original post:
If you use an array as Value… Like
‘’’
Map{“key”, array{int, int ,int…}}
‘’’
You can get and add new indexes to the array and overwrite the keys with the new array value, as you wish.
Saw a really bad practice with a struct containing all variable types, wrapped with a
an array… Like this:
‘’’
Map{“key”, array{struct{int,float,string…},…}
‘’’
Bad that is really really bad… So better create structs as value type, that absolutely fit your needs, in memory of the Memory
Thank you for pointing out the badness of my practice!
Unfortunately, I can’t find a way to set the Value to an array. Where should I look for it?
The only way I found is to use a simple structure with a variable that I set to an array container.
You could make a structure of maps (MapStruct) with a name field for array search if you like. Then Embed the MapStruct in another structure (MapArray) so you can make it an array. Then loop through and use the Map Utility options to change values.