User:Eliteofdelete: Difference between revisions

From Kolmafia
Jump to navigation Jump to search
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..."
 
imported>Eliteofdelete
Blanked the page
 
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:


== 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>
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. <br><br>
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. </p>
<pre>
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.
</pre>
The example above could be condensed to:
<pre>
[Blue Key] = Healing potion;
[Green Key] = 10 gold;
[Red Key] = Healing potion;
</pre>
Converting this into ASH, it would look like:
<syntaxhighlight>
//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");
</syntaxhighlight>
<p>
This will print, "<span style="color:#0000FF;">The Door that uses the Blue Key gives you Healing Potion</span>". <br><br>
'''Unique Keys:'''<br>
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. </p>
<syntaxhighlight>
//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");
</syntaxhighlight>
This will print, "<span style="color:#0000FF;">The Door that uses the Blue Key gives you 10 gold</span>". <br><br>
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.
<pre>
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.
</pre>
The example above could be condensed to:
<pre>
[Blue Key][#1] = Healing potion;
[Green Key][#1] = 10 gold;
[Red Key][#1] = Healing potion;
[Blue Key][#2] = Machine Gun;
</pre>
Converting this into ASH, it would look like:
<syntaxhighlight>
//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");
</syntaxhighlight>
This will print, "<span style="color:#0000FF;">The Door that uses the Blue Key #1 gives you Healing Potion and Blue Key #2 gives you Machine Gun</span>".

Latest revision as of 02:24, 25 January 2015