I’ve got a dictionary setup with some key, value pairs and I just want to be able to access them with a function, but I’m getting this error when I call my showPotion() function (see below):
KeyNotFoundException: The given key was not present in the dictionary.
Here’s how my script looks:
#pragma strict
import System.Collections.Generic;
var potions = new Dictionary.<String, int>();
function showPotion(potionName:String)
{
Debug.Log(potions["Hea1PoInt"]);
}
function Start () {
var potions = new Dictionary.<String, int>();
potions.Add("Hea1PoInt", 0);
potions.Add("Hea2PoInt", 3);
potions.Add("Hea3PoInt", 0);
potions.Add("Hea4PoInt", 0);
potions.Add("Hea5PoInt", 0);
}
I’m stumped! Can anyone shed some light on this? Thanks!