Hi guys im having a error in down script and i cant figure it out wts going wrong: Assets/Scripts/DataBase/Items/RPGItemDatabase.cs(19,56): error CS1922: A field of property 'BaseItem' cannot be initialized with a collection object initializer because type 'BaseItem' does not implement 'System.Collections.IEnumeration'Interface Can someone help plz? Appreciate. Code (CSharp): using UnityEngine; using System.Collections; using System.Collections.Generic; using System.Xml; using System.IO; public class RPGItemDatabase : MonoBehaviour { public TextAsset itemInventory; public static List<BaseItem> inventoryItems = new List<BaseItem>(); private List<Dictionary<string, string>> inventoryItemsDictionary = new List<Dictionary<string, string>> (); private Dictionary<string, string> inventoryDictionary; void Awake() { ReadItemsFromDatabase (); for (int i=0; i<inventoryItemsDictionary.Count; i++) { inventoryItems.Add(new BaseItem{inventoryItemsDictionary[i]}); } } public void ReadItemsFromDatabase() { XmlDocument xmlDocument = new XmlDocument (); xmlDocument.LoadXml (itemInventory.text); XmlNodeList itemList = xmlDocument.GetElementsByTagName ("Item"); foreach (XmlNode inteInfo in itemList) { XmlNodeList itemContent = inteInfo.ChildNodes; inventoryDictionary = new Dictionary<string, string>(); //ItemName: TestItem foreach(XmlNode content in itemContent){ switch(content.Name){ case "ItemName": inventoryDictionary.Add("ItemName", content.InnerText); break; case "ItemID": inventoryDictionary.Add("ItemID", content.InnerText); break; case "ItemType": inventoryDictionary.Add("ItemType", content.InnerText); break; } } inventoryItemsDictionary.Add(inventoryDictionary); } } }
Code (CSharp): using UnityEngine; using System.Collections; using System.Collections.Generic; [System.Serializable] //Do this in all information that need to be save, them apply in GameInformation / SaveInformation / LoadInformation public class BaseItem { private string itemName; private string itemDescription; private int itemID; private int stamina; private int endurance; private int strenght; private int intellect; private int overpower; private int luck; private int mastery; private int charisma; public enum ItemTypes{ EQUIPMENT, WEAPON, SCROLL, POTION } private ItemTypes itemType; public BaseItem() { } public BaseItem(Dictionary<string, string> itemsDictionary) { itemName = itemsDictionary["ItemName"]; itemID = int.Parse (itemsDictionary ["ItemID"]); itemType = (ItemTypes)System.Enum.Parse (typeof(BaseItem), itemsDictionary ["ItemType"].ToString ()); } public string ItemName { get{ return itemName;} set{ itemName = value;} } public string ItemDescription { get{ return itemDescription;} set{ itemDescription = value;} } public int ItemID { get{ return itemID;} set{ itemID = value;} } public ItemTypes ItemType { get{ return itemType;} set{ itemType = value;} } public int Stamina { get{ return stamina;} set{ stamina = value;} } public int Endurance { get{ return endurance;} set{ endurance = value;} } public int Strenght { get{ return strenght;} set{ strenght = value;} } public int Intellect { get{ return intellect;} set{ intellect = value;} } public int Overpower { get{ return overpower;} set{ overpower = value;} } public int Luck { get{ return luck;} set{ luck = value;} } public int Mastery { get{ return mastery;} set{ mastery = value;} } public int Charisma { get{ return charisma;} set{ charisma = value;} } }
Code (CSharp): new BaseItem{inventoryItemsDictionary[i]} Incorrect syntax here. Should use ( ) not { }