User:Eliteofdelete

From Kolmafia
Revision as of 02:12, 22 January 2015 by imported>Eliteofdelete (Created page with " == A Noob's Guide to Maps == <p> Maps are probably one of the hardest ASH concepts to understand. Hopefully this little guide will make them more understandable. <br><br> Fi...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

A Noob's Guide to Maps

Maps are probably one of the hardest ASH concepts to understand. Hopefully this little guide will make them more understandable.

First, when talking about maps and keys, we are not talking about items in Kingdom of Loathing (something I originally thought when I first read about them), but rather they refer to a concept of storing data or information in an ASH script.

A map is made up of two parts, its key(s) and their respective values. A map can have any amount of keys, but only 1 value. Also, keys will always be unique from one another. To understand this, lets take the simplest type of map, a map with 1 key each giving a value and lets use the following analogy of keys and doors.

You have a blue key, it opens door #1, and inside you find a healing potion.
You have a green key, it opens door #2, and inside you find 10 gold.
You have a red key, it opens door #3, and inside you find a healing potion.

The example above could be condensed to:

[Blue Key] = Healing potion;
[Green Key] = 10 gold;
[Red Key] = Healing potion;

Converting this into ASH, it would look like:

//Example 1
//First Define the Map
string[string] Door;
//Assigning the map
Door["Blue Key"] = "Healing Potion";
Door["Green Key"] = "10 gold";
Door["Red Key"] = "Healing Potion";
//Output
print("The Door that uses the Blue Key gives you "+Door["Blue Key"], "blue");

This will print, "The Door that uses the Blue Key gives you Healing Potion".

Unique Keys:
Remember that keys must be unique to what they are assigned too. For instance, you can not have a blue key give a Healing Potion and 10 Gold.

//Example 2
//First Define the Map
string[string] Door;
//Assigning the map
Door["Blue Key"] = "Healing Potion";
Door["Green Key"] = "10 gold";
Door["Red Key"] = "Healing Potion";
Door["Blue Key"] = "10 gold";
//Output
print("The Door that uses the Blue Key gives you "+Door["Blue Key"], "blue");

This will print, "The Door that uses the Blue Key gives you 10 gold".

The new loot item overrides the previous item it used to give. In this respect, Keys must always be unique. If you wanted the Blue Key to offer different loot types than just Healing Potions, you would have to give the Blue Key another attribute, like shape or number. The next example will have colored, numbered keys.

You have a blue, #1 key, it opens door #1, and inside you find a healing potion.
You have a green, #1 key, it opens door #2, and inside you find 10 gold.
You have a red, #1 key, it opens door #3, and inside you find a healing potion.
You have a blue, #2 key, it opens door #4, and inside you find a machine gun.

The example above could be condensed to:

[Blue Key][#1] = Healing potion;
[Green Key][#1] = 10 gold;
[Red Key][#1] = Healing potion;
[Blue Key][#2] = Machine Gun;

Converting this into ASH, it would look like:

//Example 3
//First Define the Map
string[string][int] Door;
//Assigning the map
Door["Blue Key"][1] = "Healing Potion";
Door["Green Key"][1] = "10 gold";
Door["Red Key"][1] = "Healing Potion";
Door["Blue Key"][2] = "Machine Gun";
//Output
print("The Door that uses the Blue Key #1 gives you "+Door["Blue Key"][1]+" and Blue Key #2 gives you "+Door["Blue Key"][2], "blue");

This will print, "The Door that uses the Blue Key #1 gives you Healing Potion and Blue Key #2 gives you Machine Gun".