Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by TheTopSkull · Aug 22, 2013 at 03:25 PM · compilerburgzergarcadehackandslash

Error cs1922

Hey everybody! I'm been working on BurgzergArcade's Hack and Slash tutorial and now I'm receiving these errors

Assets/Scripts/Character Class/BaseCharacter.cs(115,82): error CS1922: A field or property ModifyingAttribute' cannot be initialized with a collection object initializer because type ModifyingAttribute' does not implement `System.Collections.IEnumerable' interface

I get 12 of these and they all go to my BaseCharacter.cs and the lines they go to are my my setupskillmodifiers,

here is the script if anyone for anyone who needs it to help find the error

 using UnityEngine;
 using System.Collections;
 using System;  //added to access Enum class
 
 public class BaseCharacter : MonoBehaviour {
 private string _name;
 private int _level;
 private uint _freeExp;
     
     private Attribute[] _primaryAttribute;
     private    Vital[] _vital;
     private Skill[] _skill;
     
     public void Awake() {
         _name = string.Empty;
         _level = 0;
         _freeExp = 0;
         
         _primaryAttribute = new Attribute[Enum.GetValues(typeof(AttributeName)).Length];
         _vital = new Vital[Enum.GetValues(typeof(VitalName)).Length];
         _skill = new Skill[Enum.GetValues(typeof(SkillName)).Length];
         
         SetupPrimaryAttributes();
         SetupVitals();
         SetupSkills();
     }
     
     // Use this for initialization
     void Start () {
     
     }
     
     // Update is called once per frame
     void Update () {
     
     }
     public string Name {
         get{ return _name;}
         set{ _name = value;}
     }
     public int Level {
         get{ return _level; }
         set{ _level = value; }
     }
     public uint FreeExp {
         get{ return _freeExp;}
         set{ _freeExp = value;}
     }
     
     public void AddExp(uint exp) {
         _freeExp += exp;
         
         CalculateLevel();
     }
     
     //take the adg of all the players skills and asign that as the palyer level
     public void CalculateLevel() {
     }
     
 private void SetupPrimaryAttributes() {
 
 for(int cnt = 0; cnt < _primaryAttribute.Length; cnt++) 
 
 _primaryAttribute[cnt] = new Attribute();
         
 }
 
 private void SetupVitals() {
 for(int cnt = 0; cnt < _vital.Length; cnt++) 
 _vital[cnt] = new Vital();
                 
         SetupVitalModifiers();
 }
 private void SetupSkills() {        
 for(int cnt = 0; cnt < _skill.Length; cnt++)          
 _skill[cnt] = new Skill();
            
            SetupSkillModifiers();
 
 }
     
     public Attribute GetPrimaryAttribute(int index) {
         return _primaryAttribute[index];
     }
     public Vital GetVital(int index) {
         return _vital[index];
     }
     public Skill GetSkill(int index) {
         return _skill[index];
     }
     
     private  void SetupVitalModifiers() {
         //health 
         ModifyingAttribute health = new ModifyingAttribute();
         health.attribute = GetPrimaryAttribute((int)AttributeName.Might);
         health.ratio = 0.5f;
         
         GetVital((int)VitalName.Health).AddModifier(health);
         //stamina
         ModifyingAttribute Stamina = new ModifyingAttribute();
         Stamina.attribute = GetPrimaryAttribute((int)AttributeName.Agility);
         Stamina.ratio = 1;
         
         GetVital((int)VitalName.Stamina).AddModifier(Stamina);
         //mana
         ModifyingAttribute Mana = new ModifyingAttribute();
         Mana.attribute = GetPrimaryAttribute((int)AttributeName.Willpower);
         Mana.ratio = 1;
         
         GetVital((int)VitalName.Mana).AddModifier(Mana);
     }
     
     private void SetupSkillModifiers() {
         //melee offence
         GetSkill((int)SkillName.Melee_Offence).AddModifier(new ModifyingAttribute{GetPrimaryAttribute((int)AttributeName.Might), .33f});
         GetSkill((int)SkillName.Melee_Offence).AddModifier(new ModifyingAttribute{GetPrimaryAttribute((int)AttributeName.Agility), .33f});
         //melee defence
         GetSkill((int)SkillName.Melee_Defence).AddModifier(new ModifyingAttribute{GetPrimaryAttribute((int)AttributeName.Might), .33f});
         GetSkill((int)SkillName.Melee_Defence).AddModifier(new ModifyingAttribute{GetPrimaryAttribute((int)AttributeName.Speed), .33f});
 
         //magic offence
         GetSkill((int)SkillName.Magic_Offence).AddModifier(new ModifyingAttribute{GetPrimaryAttribute((int)AttributeName.Willpower), .33f});
         GetSkill((int)SkillName.Magic_Offence).AddModifier(new ModifyingAttribute{GetPrimaryAttribute((int)AttributeName.Intelligence), .33f});
 
         //magic defence
         GetSkill((int)SkillName.Magic_Defence).AddModifier(new ModifyingAttribute{GetPrimaryAttribute((int)AttributeName.Concentration), .33f});
         GetSkill((int)SkillName.Magic_Defence).AddModifier(new ModifyingAttribute{GetPrimaryAttribute((int)AttributeName.Charisma), .33f});
 
         //ranged offence
         GetSkill((int)SkillName.Ranged_Offence).AddModifier(new ModifyingAttribute{GetPrimaryAttribute((int)AttributeName.Speed), .33f});
         GetSkill((int)SkillName.Ranged_Offence).AddModifier(new ModifyingAttribute{GetPrimaryAttribute((int)AttributeName.Agility), .33f});
 
         //ranged defence
         GetSkill((int)SkillName.Ranged_Defence).AddModifier(new ModifyingAttribute{GetPrimaryAttribute((int)AttributeName.Might), .33f});
         GetSkill((int)SkillName.Ranged_Defence).AddModifier(new ModifyingAttribute{GetPrimaryAttribute((int)AttributeName.Speed), .33f});
 
         
     }
     public void StatUpdate() {
         for(int cnt =0; cnt < _vital.Length; cnt++)
             _vital[cnt].Update();
         
         for(int cnt = 0;cnt < _skill.Length; cnt++)
             _skill[cnt].Update();
         
 }
 }

 
Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image getyour411 · Aug 22, 2013 at 03:42 PM 0
Share

$$anonymous$$odifyingAttribute looks like its defined elsewhere, if I recall that series it's somewhere in attributes or stat classes - look at those and check syntax

avatar image TheTopSkull · Aug 22, 2013 at 04:03 PM 0
Share

well I'm really new to C# so I'm a noob to this so I'll show you where my modifying attribute is located

     private List<$$anonymous$$odifyingAttribute> _mods ;      //A list of Attributes that modify this stat
     private int _modValue;                       //The amount added to the baseValue
         
     public $$anonymous$$odifiedStat() {
         _mods = new List<$$anonymous$$odifyingAttribute>();
         
         _modValue = 0;
     }
     
     public void Add$$anonymous$$odifier($$anonymous$$odifyingAttribute mod) {
         _mods.Add(mod);
         
     }
     
     private void Calculate$$anonymous$$odValue() {
         _modValue = 0;
         
         if(_mods.Count > 0)
             foreach($$anonymous$$odifyingAttribute att in _mods)
                 _modValue += (int)(att.attribute.AdjustedBaseValue * att.ratio);
         }
     
     public new int AdjustedBaseValue {
         get{ return BaseValue + BuffValue + _modValue; }
     }
     
     public void Update() {
         Calculate$$anonymous$$odValue();
     }
     
 }
 
 public struct $$anonymous$$odifyingAttribute {
     public Attribute attribute;
     public float ratio;
avatar image getyour411 · Aug 22, 2013 at 06:22 PM 0
Share

Is there more to this script? If there isn't you are missing lines at the bottom of it.

3 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by ArkaneX · Aug 22, 2013 at 04:23 PM

You can't create ModifyingAttribute instance using syntax:

 new ModifyingAttribute{GetPrimaryAttribute((int)AttributeName.Might), .33f}

Using {xxx, yyy} tells the compiler that some collection with two elements will be created. Instead you have to use:

 new ModifyingAttribute
 {
     attribute = GetPrimaryAttribute((int)AttributeName.Might),
     ratio = 0.33f
 }

This way you create instance, with already initialized fields.

Btw - if you're using System namespace, then watch out for potential problems, because there is Attribute type defined in this namespace.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image yestian · Mar 23, 2014 at 12:21 PM 0
Share

Yes you are right .Thak you first. But How can him do that like this with none error in that video. GetSkill((int)SkillName.$$anonymous$$elee_Defence).Add$$anonymous$$odifier(new $$anonymous$$odifyingAttribute(GetPrimaryAttribute((int)AttributeName.Speed), 0.33f));

avatar image ArkaneX · Mar 23, 2014 at 09:05 PM 0
Share

Because new $$anonymous$$odifyingAttribute(x,y) is valid - it's a constructor taking 2 parameters.

avatar image
0

Answer by TheTopSkull · Aug 22, 2013 at 04:47 PM

ok I'm sorted on those errors but now I only have 3

Assets/Scripts/Character Class/BaseCharacter.cs(170,1): error CS1525: Unexpected symbol }', expecting )', or ,' Assets/Scripts/Character Class/BaseCharacter.cs(172,61): error CS0201: Only assignment, call, increment, decrement, and new object expressions can be used as a statement Assets/Scripts/Character Class/BaseCharacter.cs(172,68): error CS1525: Unexpected symbol )', expecting `;'

Here is the new code:

 public class BaseCharacter : MonoBehaviour {
 private string _name;
 private int _level;
 private uint _freeExp;
     
     private Attribute[] _primaryAttribute;
     private    Vital[] _vital;
     private Skill[] _skill;
     
     public void Awake() {
         _name = string.Empty;
         _level = 0;
         _freeExp = 0;
         
         _primaryAttribute = new Attribute[Enum.GetValues(typeof(AttributeName)).Length];
         _vital = new Vital[Enum.GetValues(typeof(VitalName)).Length];
         _skill = new Skill[Enum.GetValues(typeof(SkillName)).Length];
         
         SetupPrimaryAttributes();
         SetupVitals();
         SetupSkills();
     }
     
     // Use this for initialization
     void Start () {
     
     }
     
     // Update is called once per frame
     void Update () {
     
     }
     public string Name {
         get{ return _name;}
         set{ _name = value;}
     }
     public int Level {
         get{ return _level; }
         set{ _level = value; }
     }
     public uint FreeExp {
         get{ return _freeExp;}
         set{ _freeExp = value;}
     }
     
     public void AddExp(uint exp) {
         _freeExp += exp;
         
         CalculateLevel();
     }
     
     //take the adg of all the players skills and asign that as the palyer level
     public void CalculateLevel() {
     }
     
 private void SetupPrimaryAttributes() {
 
 for(int cnt = 0; cnt < _primaryAttribute.Length; cnt++) 
 
 _primaryAttribute[cnt] = new Attribute();
         
 }
 
 private void SetupVitals() {
 for(int cnt = 0; cnt < _vital.Length; cnt++) 
 _vital[cnt] = new Vital();
                 
         SetupVitalModifiers();
 }
 private void SetupSkills() {        
 for(int cnt = 0; cnt < _skill.Length; cnt++)          
 _skill[cnt] = new Skill();
            
            SetupSkillModifiers();
 
 }
     
     public Attribute GetPrimaryAttribute(int index) {
         return _primaryAttribute[index];
     }
     public Vital GetVital(int index) {
         return _vital[index];
     }
     public Skill GetSkill(int index) {
         return _skill[index];
     }
     
     private  void SetupVitalModifiers() {
         //health 
         ModifyingAttribute health = new ModifyingAttribute();
         health.attribute = GetPrimaryAttribute((int)AttributeName.Might);
         health.ratio = 0.5f;
         
         GetVital((int)VitalName.Health).AddModifier(health);
         //stamina
         ModifyingAttribute Stamina = new ModifyingAttribute();
         Stamina.attribute = GetPrimaryAttribute((int)AttributeName.Agility);
         Stamina.ratio = 1;
         
         GetVital((int)VitalName.Stamina).AddModifier(Stamina);
         //mana
         ModifyingAttribute Mana = new ModifyingAttribute();
         Mana.attribute = GetPrimaryAttribute((int)AttributeName.Willpower);
         Mana.ratio = 1;
         
         GetVital((int)VitalName.Mana).AddModifier(Mana);
     }
     
     private void SetupSkillModifiers() {
         //melee offence
        ((int)SkillName.Melee_Offence).AddModifier(new ModifyingAttribute{
              attribute = GetPrimaryAttribute((int)AttributeName.Might),
              ratio = 0.33f
         }
                  ((int)SkillName.Melee_Offence).AddModifier(new ModifyingAttribute{
              attribute = GetPrimaryAttribute((int)AttributeName.Agility),
              ratio = 0.33f
         }
         
         //melee defence
          ((int)SkillName.Melee_Defence).AddModifier(new ModifyingAttribute{
              attribute = GetPrimaryAttribute((int)AttributeName.Might),
              ratio = 0.33f
         }
                  ((int)SkillName.Melee_Defence).AddModifier(new ModifyingAttribute{
              attribute = GetPrimaryAttribute((int)AttributeName.Speed),
              ratio = 0.33f
         }
 
         //magic offence
                  ((int)SkillName.Magic_Offence).AddModifier(new ModifyingAttribute{
              attribute = GetPrimaryAttribute((int)AttributeName.Concentration),
              ratio = 0.33f
         }
     
         //magic defence
                  ((int)SkillName.Magic_Defence).AddModifier(new ModifyingAttribute{
              attribute = GetPrimaryAttribute((int)AttributeName.Intelligence),
              ratio = 0.33f
         }
                  ((int)SkillName.Magic_Defence).AddModifier(new ModifyingAttribute{
              attribute = GetPrimaryAttribute((int)AttributeName.Charisma),
              ratio = 0.33f
         }
 
         //ranged offence
                  ((int)SkillName.Ranged_Offence).AddModifier(new ModifyingAttribute{
              attribute = GetPrimaryAttribute((int)AttributeName.Agility),
              ratio = 0.33f
         }
                  ((int)SkillName.Ranged_Offence).AddModifier(new ModifyingAttribute{
              attribute = GetPrimaryAttribute((int)AttributeName.Agility),
              ratio = 0.33f
         }
 
         //ranged defence
                  ((int)SkillName.Ranged_Defence).AddModifier(new ModifyingAttribute{
              attribute = GetPrimaryAttribute((int)AttributeName.Speed),
              ratio = 0.33f
         }
                  ((int)SkillName.Ranged_Defence).AddModifier(new ModifyingAttribute{
              attribute = GetPrimaryAttribute((int)AttributeName.Agility),
              ratio = 0.33f
         }
     
 }
     public void StatUpdate() {
             for(int cnt = 0; cnt < _vital.Length; cnt++)
             _vital[cnt].Update();
         
         for(int cnt = 0;cnt < _skill.Length; cnt++)
             _skill[cnt].Update();
         
         }
 }
Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ArkaneX · Aug 22, 2013 at 06:05 PM 2
Share

@TheTopSkull - unfortunately your code has a lot more errors. $$anonymous$$ultiple parentheses and semicolons is missing, int type doesn't have AddProperty method (unless added as an extension), and possible a few more, which are covered by those I'm able to find.

Unity Answers is not an online compiler. You have to get a basic knowledge of C# - there are a lot of tutorials online, for example here or here.

Without this knowledge, you will quickly get frustrated and stop your adventure with Unity.

avatar image TheTopSkull · Aug 22, 2013 at 06:25 PM 0
Share

thanks ArkaneX hopefully next time you see me I'll know allot more about C# and unity!

avatar image
0

Answer by getyour411 · Aug 22, 2013 at 05:10 PM

I've gone through that entire HackNSlash tut and Petey never leaves you with code with doesn't compile due to syntax or other errors, so I would not advise changing anything since you don't know what you are really changing. Put it back to how it was and look at his next video in the series, sometimes he hits his cutoff point in one vid but fixes it at the start of the next. Anything else is a typo somewhere.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image TheTopSkull · Aug 22, 2013 at 06:06 PM 0
Share

Dude I've checked and the first basecharacter.cs I posted never worked and I have the code down to a tee, to only change I've actually made is the name of the attributes and thats about it

avatar image getyour411 · Aug 22, 2013 at 06:18 PM 0
Share

If you changed the names of the attributes, did you also change the names in the Enum and all other places where his names were referenced? I've seen a ton of feedback on his YouTube channel and it all comes down to typos, cAse errors, etc. Heck give him ~10 bucks and he'll give you every script

Check your $$anonymous$$odifiedStat.cs - the one you posted above is missing a few lines at the bottom.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

18 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

A node in a childnode? 1 Answer

Unity BurgZergArcade Tutorial 20 errors. 1 Answer

CS8025 error 1 Answer

How do i fix a Compiler error 2 Answers

Sort Two Arrays 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges