Wow. That's a big question. Maps...
A map is a way of dealing with variables that can be grouped together. It allows you to perform the same action on a number of variables while keeping physical code down. They can also act as a form of hard memory, to back up various variables if you are exiting and re-calling a script.
Maps are given one or more properties by which they are placed. The most common of these is a number (integer), which can then be called. These properties have to be defined when the map is created, and are then used to call the map's contents. In addition, the map contents themselves have to be defined (string, int, location, monster, etc). Basically, it is an association between one data type and another.
For example:
Code:
string [int] example_map;
This has created a map into which we will enter strings, with an integer data type associated with each string. Now to populate the map:
Code:
example_map[0] = "Example string one";
example_map[1] = "Example string two";
We now have a map that contains two strings, each associated with a different integer.
Now, to retrieve the data type:
Code:
foreach n in example_map
{
print(example_map[n]);
}
This takes every data type. Another way to search would be by specifying an integer. Let's populate the map a little more:
Code:
map_example[2] = "Example string three";
map_example[3] = "Example string four";
And now specify a starting integer:
Code:
for n from 1 upto 3
{
print(example_map[n]);
}
This time, we are specifying the map within our function, so no need to use the "in" statement.
Putting the code together:
Code:
string [int] example_map;
example_map [0] = "Example string one";
example_map [1] = "Example string two";
foreach n in example_map
{
print(example_map[n]);
}
print( "Finished my foreach... onto using integers" , "blue" );
example_map [2] = "Example string three";
example_map [3] = "Example string four";
for n from 1 upto 3
{
print(example_map[n]);
}
Hope that has helped slightly.