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 matteonite · Jun 30, 2012 at 09:26 PM · errortutorialburgzergarcade

Unity BurgZergArcade Tutorial 20 errors.

So I have been following BurgZergArcade's unity tutorials and i have been loving it but i am up to 20 and ever since i started 18-20(BaseCharacter.cs Tutorials) i have been getting errors in my BaseCharacter Script, There are like 5 main errors than they start to repeat. It seems it cant get access to my other classes. Here are some errors:

Assets/Scripts/Character Classes/BaseCharacter.cs(124,57): error CS1503: Argument #1' cannot convert object' expression to type ModifyingAttribute' Assets/Scripts/Character Classes/BaseCharacter.cs(124,57): error CS1502: The best overloaded method match for ModifiedStat.AddModifier(ModifyingAttribute)' has some invalid arguments

Assets/Scripts/Character Classes/BaseCharacter.cs(124,149): error CS1729: The type ModifyingAttribute' does not contain a constructor that takes 2' arguments

Assets/Scripts/Character Classes/BaseCharacter.cs(124,92): error CS1503: Argument #1' cannot convert object' expression to type int' Assets/Scripts/Character Classes/BaseCharacter.cs(124,92): error CS1502: The best overloaded method match for BaseCharacter.GetPrimaryAttribute(int)' has some invalid arguments

Assets/Scripts/Character Classes/BaseCharacter.cs(124,117): error CS0103: The name AttributeName' does not exist in the current context Assets/Scripts/Character Classes/BaseCharacter.cs(33,56): error CS1502: The best overloaded method match for System.Enum.GetValues(System.Type)' has some invalid arguments

-------------------------------Fin

And here is my code or script:

using UnityEngine; using System.Collections; using System; //added to acess enum class using System.Collections.Generic;

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();
 }
 
 
 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 average of all players skills and assign that as player 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++){
         _primaryAttribute[cnt] = new Attribute();
     }        
 }
 
 private void SetupSkills(){
     for(int cnt = 0; cnt <_skill.Length; cnt++){
         _primaryAttribute[cnt] = new Attribute();
     }    
 }    
 
 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
     GetVital((int)VitalName.Health).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Constitution), .5f));
     //energy
     GetVital((int)VitalName.Energy).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Constitution), 1));
     //mana
     GetVital((int)VitalName.Mana).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Willpower), 1));
 }
 
 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.Nimbleness), .33f));
     //melee _defence
     GetSkill((int)SkillName.Melee_Defence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Speed), .33f));
     GetSkill((int)SkillName.Melee_Defence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Constitution), .33f));
     //magic offence
     GetSkill((int)SkillName.Magic_Offence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Concentration), .33f));
     GetSkill((int)SkillName.Magic_Offence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Willpower), .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.Willpower), .33f));
     //ranged offence
     GetSkill((int)SkillName.Ranged_Offence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Concentration), .33f));
     GetSkill((int)SkillName.Ranged_Offence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Speed), .33f));
     //ranged defence
     GetSkill((int)SkillName.Ranged_Defence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Speed), .33f));
     GetSkill((int)SkillName.Ranged_Defence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Nimbleness), .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();    
     
 }    

} ----------------------------fin

So if you could find my errors it would mean the world to me, this series means alot to me and it is very interesting and i would hate to get stuck here. Ask me any questions if you need more info.

Thank you so much.

Comment
Add comment · Show 5
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 Berenger · Jun 30, 2012 at 09:29 PM 0
Share

What are the lines with the error ?

avatar image matteonite · Jun 30, 2012 at 09:42 PM 0
Share

I don't know that is why i am asking what is wrong lol. If you need more info to answer my question plz ask

avatar image matteonite · Jun 30, 2012 at 09:42 PM 0
Share

i thinks the "Using System;" doesnt work

avatar image Berenger · Jun 30, 2012 at 09:52 PM 0
Share

Which one is the line 124 ? And 33 ? (using System; is ok, that's not the problem)

avatar image matteonite · Jun 30, 2012 at 10:09 PM 0
Share

i dont know,

1 Reply

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

Answer by the_Simian · Jun 30, 2012 at 10:14 PM

Okay Here we go:

Assets/Scripts/Character Classes/BaseCharacter.cs(124,57): error CS1503: Argument #1' cannot convertobject' expression to type ModifyingAttribute' you are missing **curly brackets** for your ModifyingAttribute object you are creating. **you are using parenthesis, on accident!** Do it like this (Unity 3): ---------- GetVital((int) VitalName.Health).AddModifier(new ModifyingAttribute **{** attribute = GetPrimaryAttribute((int) AttributeName.Constitution), ratio = 0.5 **}**); ---------- I bolded the part you got wrong. > Assets/Scripts/Character > Classes/BaseCharacter.cs(124,57): > error CS1502: The best overloaded > method match for > ModifiedStat.AddModifier(ModifyingAttribute)' has some invalid arguments

Assets/Scripts/Character Classes/BaseCharacter.cs(124,149): error CS1729: The type ModifyingAttribute' does not contain a constructor that takes2' arguments

Same thing for these as well.... looks like the other errors might be related.

let me explain what is going on...

You are running the method GetVital(), [and passing in an (int) you are getting from an enumeration], and then after that, running AddModifier().

The problem is in the second function, "AddModifier()"

the problem is the argument you are passing into the Add Modifier. The AddModifier expects an object that is of type ModifyingAttribute. In your case, since you are missing those brackets.... the compiler thinks you are passing objects of the wrong type! In truth.. the new ModifyingAttribute is what needs that int for its first argument, attribute.

So basically each AddModifier takes 2 args: the attribute, which takes an Attribute, and the ratio which takes a float (or double in my project). the Attribute is returned from GetPrimaryAttribute(). GetPrimaryAttribute() takes an int. We are getting the int by casting an enum as an int.

so swap those parenthesis for curly brackets to properly 'new up' what you need!

Edit: to be clear, I think it goes without saying you made the exact same mistake on every VitalModifier line and SkillModifierLine. thats why you have a bunch of duplicate errors. Check out Petey's video again,and you'll see the slip up. If you want to learn more about this technique its called Object Initializers. Read more here: http://msdn.microsoft.com/en-us/library/bb397680.aspx

And be sure to mark this as the answer if it fixed your code.

Comment
Add comment · Show 5 · 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 matteonite · Jul 02, 2012 at 09:02 PM 0
Share

Thanks for the answer but i still have a few errors, you only cut my erros amount from 87 to 48

avatar image matteonite · Jul 02, 2012 at 09:29 PM 0
Share

How do you mark this as the answer?

avatar image matteonite · Jul 02, 2012 at 09:29 PM 0
Share

well .. and almost complete answer..

avatar image the_Simian · Jul 02, 2012 at 11:49 PM 0
Share

To mark the answer correct: Click the checkmark below the up/down vote buttons.

I saw you posted elsewhere for the remaining problems, and I will answer those questions there (if I can). Anyways, since this resolved (according to you) 39 compiler issues for you, thanks in advance for marking the answer as correct. Its useful, because it helps train the search engines to help others find the answers they need more easily and marking the right answers helps user members willing to help fix your problems by giving them reputation.

Also, I see you are a new user- welcome to Unity Answers. my advice in the future is to break up your questions into more 'discrete parts'. This i good because it helps people when searching in the future. what I am saying is that generally means do not post 80 compiler errors on a single question (unless they are all definitely related). Ins$$anonymous$$d, try to narrow down to one 'type' of compiler error, and post a different 'type' as a separate question. That way the wiki works best for everyone, such as those searching from Google. it also helps us troubleshoot your problems and get you up and running faster!

One last handy piece of advice. You can edit your responses by clicking the pencil icon by your name. This way you don't have to reply repeatedly- you can type everything you want in a single comment. If you add a ton of replies- it will push other's replies further down the que making it generally less readable...and less likely you'll get that golden nugget of information you need to fix your project :)

I hope all the information is useful, dude!

avatar image matteonite · Jul 03, 2012 at 07:01 PM 0
Share

Thanks For the helpful info, If you could help me with my other errors that would be great thanks

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

6 People are following this question.

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

Related Questions

Unity Car Tutorial Error 0 Answers

BurgZergArcade tutorial 20 errors? 0 Answers

error CS0103: The name `AttributeName' does not exist in the current context 0 Answers

Error CS1503, Error CS1502 1 Answer

A node in a childnode? 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