This post is ment to explain the single most powerful data type that the LPC language has besides objects. The mapping indexes its information using "flags" in additon to numbers. It is perfered however that you dont bother with the numbers. I have mentioned it mearly to let you know you CAN do it that way. You will see shortly tho that there is no point in it.

The mapping data type is able to store ANY of the data types. You may have anything act as the "flag" or "key" on the mapping to point at your "values" stored on the mapping. The simplest mapping is basically two arrays with the "key" on the first one pointing at the "value" on the other one. It gets much more indepth however when we start talking about multiple dimentional mappings. This is where the mappings REAL power comes into play. I will explain that in the part 2 to mappings.

--------------------------------------------------------------------------------
DEFINING a mapping >>>

mapping guards;

INITIATING a mapping >>>

guards=([]);

Just like in arrays and other variable types. You can cut right to the chase and define, initiate and assign a value to a mapping right when you define them.

--------------------------------------------------------------------------------
==============Assigning values ===================

Once you initated your mapping. You can start assigning information to be stored on it. As i stated, the mapping can store multiple forms of data all at once. I'm going to get a little complex here so that i may demonstrate this idea.

I stated above that the mapping uses "keys" to index the "values" on the mapping.
You assign these values as follows;

guards["name"]="Dragon Warriors";
guards["members"] =({"yakko","windigo","echelon"});
guards["equip"] = ({"cloak","helm","knife"});
guards["min_lvl"] = 20;
guards["max_size"] = 35;

As you can see, I have stored quite a bit of information on the mapping guards. There are strings, arrays of strings, and ints on the mapping. The "keys" i spoke about are the [" "] items next to guards. The "values" are the items to the right of the = operator.

If you were to return guards at this time, you would get the following;

([ "name":"Dragon Warriors", "members":({"yakko","windigo","echelon"}), "equip":({"cloak","helm","knife"}), "min_lvl":20, "max_size":35 ])

====================================================
================ INDEXING for mappings ================

Now that we got information stored, How do we get it back ??

Lets say you wish to know the value @ "max_size" of guards. You would index this with guards["max_size"] and get the value 35 returned to you.

When you talk about multiple dimentional mappings, YOu need 2d indexing. This is simple on mappings tho :) Say you wish to see the second member of the values set on the array "members" . You would index it as guards["members"][1].

==========Functions used with mappings ============

The function keys() returns the keys for the mapping. In the case of guards, the value returned would be an array with the contents ({"name","members","equip","min_lvl","max_size"}) . 

The function values() returns the values for each of the matching "keys" returned by the keys() functions.

The function map_delete() removes a key from the mapping.
