- Home /
Item/Database Error
Anyone catch what is wrong here? I been trying for an hour now.
itemPower =int.Parse (dict["itemPower"]);
itemSpeed = int.Parse (dict["itemSpeed"]);
itemType = System.Enum.Parse(typeof (Item.ItemType), dict["itemType"].ToString());
multiItems = bool.Parse(dict["multiItems"]);
itemCounter = multiItems ? 1 : 0;
This is is a sample of the line of code that is throwing me this error:
Assets/Scripts/Item.cs(49,17): error CS0266: Cannot implicitly convert type object' to
Item.ItemType'. An explicit conversion exists (are you missing a cast?)
Try setting Using System; at the top and then change the line to this:
itemType = (Item.ItemType)Enum.Parse(typeof (Item.ItemType), dict["itemType"].ToString());
Answer by Hrungdak · Mar 27, 2015 at 07:20 AM
You are missing a cast. Try:
itemType = (Item.ItemType)System.Enum.Parse(typeof (Item.ItemType), dict["itemType"].ToString());
Answer by MakakWasTaken · Mar 27, 2015 at 03:17 PM
Or try this:
Item.ItemType ref;
if (Enum.TryParse(dict["itemType"].ToString(), out ref)) {
Debug.Log("The parsing was a success");
} else {
Debug.LogError(dict["itemType"].ToString() + " couldn't be parsed!");
}
Still with the using System;
Your answer
Follow this Question
Related Questions
How to create complex item system in an elegant way 0 Answers
Best way to display long texts 0 Answers
How to read data from a constantly updating xml server? 1 Answer
Help on making a Database. 0 Answers
How to load this XML File? 1 Answer