Figure 9.

4.3 Retrieving the object from the backpack

TakeObjectFromBackPack(string objectKey) was created to be able to take out a single, specific object from the backpack, founded by the inserted Key into the function. Function was only ran, if received Key was not an empty string or if there is at least one object in the backpack. The retrieval from the dictionary is very simple, since no looping is needed (in general). By default, object can be retrieved only when specific Key is known. If it is known, it is only a single line of code, where retrievedObject is equal to backpackObjects value retrieved by the Key. However, if exact Key is not known, only ObjectType, some looping is required. This is useful, for example when retrieving any apple from the dictionary, when player presses a button to eat some apple (assuming that Apple_1 or any random apple type no longer exists, it will retrieve Apple_2 or other). The list of same ObjectTypes is created by another function called GenerateSameTypeObjectList(objectKey). After function is called, list and count of unique ObjectTypes as apples is generated. After that, loop finds the first ObjectType (most often it is looped once, since e.g. type of Apple_1 is most common as any new apple inserted in the dictionary will receive such key value automatically in this implementation) and instantiates such game object in front of the player.