- Home /
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.
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
Which one is the line 124 ? And 33 ? (using System; is ok, that's not the problem)
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 argumentsAssets/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.
Thanks for the answer but i still have a few errors, you only cut my erros amount from 87 to 48
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!
Thanks For the helpful info, If you could help me with my other errors that would be great thanks
Your answer
Follow this Question
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