Search Unity

Script Error

Discussion in 'Scripting' started by Paykoman, Nov 20, 2014.

  1. Paykoman

    Paykoman

    Joined:
    Jun 26, 2014
    Posts:
    500
    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):
    1. using UnityEngine;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using System.Xml;
    5. using System.IO;
    6.  
    7. public class RPGItemDatabase : MonoBehaviour
    8. {
    9.     public TextAsset itemInventory;
    10.     public static List<BaseItem> inventoryItems = new List<BaseItem>();
    11.  
    12.     private List<Dictionary<string, string>> inventoryItemsDictionary = new List<Dictionary<string, string>> ();
    13.     private Dictionary<string, string> inventoryDictionary;
    14.  
    15.     void Awake()
    16.     {
    17.         ReadItemsFromDatabase ();
    18.         for (int i=0; i<inventoryItemsDictionary.Count; i++) {
    19.             inventoryItems.Add(new BaseItem{inventoryItemsDictionary[i]});  
    20.         }
    21.     }
    22.  
    23.     public void ReadItemsFromDatabase()
    24.     {
    25.         XmlDocument xmlDocument = new XmlDocument ();
    26.         xmlDocument.LoadXml (itemInventory.text);
    27.         XmlNodeList itemList = xmlDocument.GetElementsByTagName ("Item");
    28.  
    29.         foreach (XmlNode inteInfo in itemList) {
    30.             XmlNodeList itemContent = inteInfo.ChildNodes;
    31.             inventoryDictionary = new Dictionary<string, string>();    //ItemName: TestItem
    32.  
    33.             foreach(XmlNode content in itemContent){
    34.                 switch(content.Name){
    35.                 case "ItemName":
    36.                     inventoryDictionary.Add("ItemName", content.InnerText);
    37.                     break;
    38.                 case "ItemID":
    39.                     inventoryDictionary.Add("ItemID", content.InnerText);
    40.                     break;
    41.                 case "ItemType":
    42.                     inventoryDictionary.Add("ItemType", content.InnerText);
    43.                     break;
    44.                 }
    45.             }
    46.  
    47.             inventoryItemsDictionary.Add(inventoryDictionary);
    48.         }
    49.     }
    50. }
    51.  
     
  2. Deleted User

    Deleted User

    Guest

    Show us your BaseItem class.
     
  3. Paykoman

    Paykoman

    Joined:
    Jun 26, 2014
    Posts:
    500
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4.  
    5. [System.Serializable]                //Do this in all information that need to be save, them apply in GameInformation / SaveInformation / LoadInformation
    6. public class BaseItem
    7. {
    8.     private string itemName;
    9.     private string itemDescription;
    10.     private int itemID;
    11.  
    12.     private int stamina;
    13.     private int endurance;
    14.     private int strenght;
    15.     private int intellect;
    16.     private int overpower;
    17.     private int luck;
    18.     private int mastery;
    19.     private int charisma;
    20.  
    21.     public enum ItemTypes{
    22.         EQUIPMENT,
    23.         WEAPON,
    24.         SCROLL,
    25.         POTION
    26.     }
    27.  
    28.     private ItemTypes itemType;
    29.  
    30.     public BaseItem()
    31.     {
    32.  
    33.     }
    34.  
    35.     public BaseItem(Dictionary<string, string> itemsDictionary)
    36.     {
    37.         itemName = itemsDictionary["ItemName"];
    38.         itemID = int.Parse (itemsDictionary ["ItemID"]);
    39.         itemType = (ItemTypes)System.Enum.Parse (typeof(BaseItem), itemsDictionary ["ItemType"].ToString ());
    40.     }
    41.  
    42.     public string ItemName
    43.     {
    44.         get{ return itemName;}
    45.         set{ itemName = value;}
    46.     }
    47.  
    48.     public string ItemDescription
    49.     {
    50.         get{ return itemDescription;}
    51.         set{ itemDescription = value;}
    52.     }
    53.  
    54.     public int ItemID
    55.     {
    56.         get{ return itemID;}
    57.         set{ itemID = value;}
    58.     }
    59.  
    60.     public ItemTypes ItemType
    61.     {
    62.         get{ return itemType;}
    63.         set{ itemType = value;}
    64.     }
    65.  
    66.     public int Stamina
    67.     {
    68.         get{ return stamina;}
    69.         set{ stamina = value;}
    70.     }
    71.  
    72.     public int Endurance
    73.     {
    74.         get{ return endurance;}
    75.         set{ endurance = value;}
    76.     }
    77.  
    78.     public int Strenght
    79.     {
    80.         get{ return strenght;}
    81.         set{ strenght = value;}
    82.     }
    83.  
    84.     public int Intellect
    85.     {
    86.         get{ return intellect;}
    87.         set{ intellect = value;}
    88.     }
    89.  
    90.     public int Overpower
    91.     {
    92.         get{ return overpower;}
    93.         set{ overpower = value;}
    94.     }
    95.  
    96.     public int Luck
    97.     {
    98.         get{ return luck;}
    99.         set{ luck = value;}
    100.     }
    101.  
    102.     public int Mastery
    103.     {
    104.         get{ return mastery;}
    105.         set{ mastery = value;}
    106.     }
    107.  
    108.     public int Charisma
    109.     {
    110.         get{ return charisma;}
    111.         set{ charisma = value;}
    112.     }
    113. }
    114.  
     
  4. A.Killingbeck

    A.Killingbeck

    Joined:
    Feb 21, 2014
    Posts:
    483
    Code (CSharp):
    1. new BaseItem{inventoryItemsDictionary[i]}
    Incorrect syntax here. Should use ( ) not { }
     
  5. Paykoman

    Paykoman

    Joined:
    Jun 26, 2014
    Posts:
    500
    Has i thought ty m8 the damm () {} [] loool
    Appreciate ur help