You’ll need to be able to work with groups or collections of items. A game that only has one character with one quest and with one shop that sells one item isn’t going to be very fun. You have choices and this episode continues more than a week long exploration of collection types available. You’ll learn when to use each type of collection and why. Up today is the dictionary. I’ll explain what dictionaries are and then give you some guidance on when to use them.

Let’s say that you wanted to map some strings to numeric values. You could use a dictionary and declare it like this. This assumes the dictionary class is actually called a map.

map numericValues;

You can then use your map to add a value like this:
numericValues[“mega”] = 1000000;

This will add a new entry with the key “mega” and the value 1,000,000 or one million.

Depending on how you declare you dictionary, you can store different types. It will always associate the keys with the values. Dictionaries are very efficient at looking up values as long as you know the key.