Here’s my dictionary:
public Dictionary<string, int> foodWeight = new Dictionary<string, int>();
foodWeight.Add("cake", 1);
and here’s where the issue occurs (its at the first foodWeight line):
for (int i = 0; i < foods.foodItems.Length; i++)
{
if (foods.currentHungerPoints >= 1400
&& inventory.weight + foodWeight[foods.foodItems*] < 30*
&& inventory.size + foodSize[foods.foodItems*] < 40)*
{
numOfCakes += 1;
inventory.weight += foodWeight[foods.foodItems*];*
inventory.size += foodSize[foods.foodItems*];*
Destroy(other.gameObject);
Here is my foods script pertaining to foodItems:
public string[] foodItems;
foodItems = new string[2];
foodItems[0] = “cake”;
Edit: I’ve debugged the crap out of this and I still have no clue. It will literally work correctly if I put in 0, but if I make the for loop put in the 0 it conks out!
Edit: This is my full error message if that changes anything → KeyNotFoundException: The given key was not present in the dictionary.
System.Collections.Generic.Dictionary`2[System.String,System.Int32].get_Item (System.String key) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Collections.Generic/Dictionary.cs:150)
InventoryItems.OnTriggerStay (UnityEngine.Collider other) (at Assets/Player/InventoryItems.cs:44)