AddMapElement

Map command

Syntax

Creates the entry for a key and makes it the current entry. An entry that already exists is reset to the default value.

AddMapElement(<map>(), <key> [, <flags>])

Parts

<map>The map, written with its empty parentheses: stock(). It must be a NewMap variable or a map field of a record.
<key>The key. It is turned into text, so 1 and "1" are the same key. Keys are case-sensitive.
<flags>Optional. Must be 0, the default.

Returns

Always 1.

Good to know

  • AddMapElement on an existing key does not add a second entry: it puts the default value back (0, "" or an empty record). To write a value without that reset, assign it: m("key") = v.
  • The entry becomes current, so m() reads or writes it right away.
  • Any <flags> other than 0 stops the program: "Aukimi maps preserve unique keys; AddMapElement flags must be 0". PureBasic's #PB_Map_NoElementCheck has no equivalent.
  • A wrong number of arguments, or an argument that is not a map, is a compile error.

Example

NewMap stock.i()stock("apple") = 7Console(Str(AddMapElement(stock(), "pear")))   ' 1stock() = 5AddMapElement(stock(), "apple")Console(MapKey(stock()) + " " + Str(stock()))   ' apple 0Console(Str(MapSize(stock())))   ' 2
In the manual : Arrays, lists and maps