x


Hack and Slash Tutorial Problem

Here we go again. This same line was used in another script, but it compiled just fine. Here is the entire code:

using UnityEngine; using System.Collections; using System; //access to 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();
}

public string Name {
set{ return _name; }
get{ _name= value; }    

}

public int Level {
set { return _level; }
get { _level= value; }  
}

public uint FreeExp {
set { return _freeExp; }
get { _freeExp= value; }
}

public void AddExp(uint exp){
    _freeExp+= exp;
    CalculateLevel();
}

//take average of all player's skills and assign that as the 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++) {
    _primaryVitals[cnt]=new Vital();   
    }
}

private void SetupSkills() {
    for(int cnt=0; cnt < _skill.Length; cnt++) {
    _primarySkills[cnt]=new Skill();   
    }
}
public Attribute GetPrimaryAttribute(int index) {
    return _primaryAttribute[index];
}

public Vital GetVitals(int index) {
    return _vital[index];
}

public Skill GetSkill(int index) {
    return _skill[index];
}

private void SetupVitalModifers() {
    // health
    GetVital=((int)VitalName.Life).AddModifer( new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Constitution ), .5f));

    //energy
    GetVital=((int)VitalName.Energy).AddModifer(new ModifyingAttribute (GetPrimaryAttribute((int)AttributeName.Constitution ), 1));

    //mana
    GetVital=((int)VitalName.Mana).AddModifer( new ModifyingAttribute (GetPrimaryAttribute((int)AttributeName.Willpower ),  1)); 

}

private void SetupSkillModifers(){
    //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.Nibleness), .33f));
    //melee defense
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 offense
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 defense
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 offense
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 defense
GetSkill((int)SkillName.Ranged_Defence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Speed), .33f));
GetSkill((int)SkillName.Ranged_Defence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Nibleness), .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();
}

} The name value doe not exist, yet in BaseStat, it worked just fine as a setter and getter. public int ExpToLevel { get{ return _expToLevel;} set{ _expToLevel=value;} } Other Errors: Assets/Scripts/Character Classes/BaseCharacter.cs(31,14): error CS0127: BaseCharacter.Name.set': A return keyword must not be followed by any expression when method returns void Assets/Scripts/Character Classes/BaseCharacter.cs(31,14): error CS0029: Cannot implicitly convert typestring' to void' Assets/Scripts/Character Classes/BaseCharacter.cs(37,15): error CS0127:BaseCharacter.Level.set': A return keyword must not be followed by any expression when method returns void Assets/Scripts/Character Classes/BaseCharacter.cs(37,15): error CS0029: Cannot implicitly convert type int' tovoid' Assets/Scripts/Character Classes/BaseCharacter.cs(42,15): error CS0127: `BaseCharacter.FreeExp.set': A return keyword must not be followed by any expression when method returns void Please help! Thanks!

more ▼

asked Feb 23 '12 at 03:52 AM

Gilead7 gravatar image

Gilead7
117 18 32 39

may I ask where you found that tutorial?

Feb 23 '12 at 07:54 AM ZweiD
(comments are locked)
10|3000 characters needed characters left

2 answers: sort oldest

you swapped the getters and setters in your code.

public int MyValue {
  get { return _myValue; }
  set { _myValue = value; }
}
more ▼

answered Feb 23 '12 at 07:45 AM

ZweiD gravatar image

ZweiD
51 1 2 3

one issue down, now it;s saying _primaryVital doesn't exist in this context. I need to therefore define it somewhere. Right?

Feb 23 '12 at 06:22 PM Gilead7

Okay, I changed some variable names around and got past that portion. This next part I have no idea.

Feb 23 '12 at 06:30 PM Gilead7
(comments are locked)
10|3000 characters needed characters left

private void SetupVitalModifers() { // health GetVital=((int)VitalName.Life).AddModifer( new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Constitution ), .5f));

    //energy
    GetVital=((int)VitalName.Energy).AddModifer(new ModifyingAttribute (GetPrimaryAttribute((int)AttributeName.Constitution ), 1));

    //mana
    GetVital=((int)VitalName.Mana).AddModifer( new ModifyingAttribute (GetPrimaryAttribute((int)AttributeName.Willpower ),  1)); 

}

Assets/Scripts/Character Classes/BaseCharacter.cs(89,48): error CS1061: Type int' does not contain a definition forAddModifer' and no extension method AddModifer' of typeint' could be found (are you missing a using directive or an assembly reference?) Are they not supposed to be cast as ints?

more ▼

answered Feb 23 '12 at 11:17 PM

Gilead7 gravatar image

Gilead7
117 18 32 39

where in your code did you define AttributeName?

reasoning from their name, they probably are strings. you can't just cast strings to ints, you need to provide something different.

Feb 24 '12 at 08:49 AM ZweiD
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x123
x3

asked: Feb 23 '12 at 03:52 AM

Seen: 678 times

Last Updated: Feb 24 '12 at 08:49 AM