cxAlex wrote:If you are using @ to get the pointer to a map-element while creating it, the map element is not created.
Here is documentation from AddMapElement() in the Map library:
This function isn't mandatory when dealing with maps, as elements are automatically added when affecting a value to them.
I would deduce that you didn't create a map-element because you didn't affect a value to it. You can't get the address of a new map element with the @ operator at the time of assignment because the @ operator cannot be used on the left side of the equation (i.e. can't use '@myMap("lol") = 3') and this isn't syntactically correct for any portion of the left side of an equation either.
The proper way would be to use the AddMapElement() command because it performs the assignment/creation and returns the address.
Code: Select all
NewMap myMap.i()
Debug @myMap("haha") ;element hasn't been assigned anything, thus not created yet
Debug AddMapElement(myMap(),"lol") ;this is the correct way to create a map element and return its address
ForEach myMap()
Debug MapKey(myMap())
Next
By the way, the address that is returned for an uncreated element is always the same, no matter what the key is. I am not sure what the address points to. I think that is a bug that probably needs to be addressed. I would suggest it = 0 if the element doesn't exist.