- Home /
The type or namescape name 'ModifyingAttribute' could not be found.
Hey guys, I've gotten this error (error CS0246) and I'm a little confused because I don't see anything wrong with the code? I've had someone else proof check it to make sure it is actually okay, but he can't see an error either. Are be both just being stupid?
The error is on this code:
private void SetupVitalModifiers() {
//health
ModifyingAttribute healthModifier = new ModifyingAttribute();
healthModifier.attribute = GetPrimaryAttribute((int)AttributeName.Constitution);
healthModifier.ratio = .5f;
GetVital((int)VitalName.Health).AddModifier(healthModifier);
//energy
ModifyingAttribute energyModifier = new ModifyingAttribute();
energyModifier.attribute = GetPrimaryAttribute((int)AttributeName.Constitution);
energyModifier.ratio = .5f;
GetVital((int)VitalName.Energy).AddModifier(energyModifier);
//mana
ModifyingAttribute manaModifier = new ModifyingAttribute();
manaModifier.attribute = GetPrimaryAttribute((int)AttributeName.Willpower);
manaModifier.ratio = .5f;
GetVital((int)VitalName.Mana).AddModifier(manaModifier);
}
Here's the full code:
using UnityEngine;
using System.Collections;
using System; // Added to access the 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(VitalName)).Length];
}
// 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 average of all of the players 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++) {
_vital[cnt] = new Vital();
}
}
private void SetupSkills() {
for(int cnt = 0; cnt < _skill.Length; cnt++) {
_skill[cnt] = new Skill();
}
}
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 healthModifier = new ModifyingAttribute();
healthModifier.attribute = GetPrimaryAttribute((int)AttributeName.Constitution);
healthModifier.ratio = .5f;
GetVital((int)VitalName.Health).AddModifier(healthModifier);
//energy
ModifyingAttribute energyModifier = new ModifyingAttribute();
energyModifier.attribute = GetPrimaryAttribute((int)AttributeName.Constitution);
energyModifier.ratio = .5f;
GetVital((int)VitalName.Energy).AddModifier(energyModifier);
//mana
ModifyingAttribute manaModifier = new ModifyingAttribute();
manaModifier.attribute = GetPrimaryAttribute((int)AttributeName.Willpower);
manaModifier.ratio = .5f;
GetVital((int)VitalName.Mana).AddModifier(manaModifier);
}
private void SetupSkillModifiers() {
}
}
And here is the code to where BaseCharacter.cs is relating to:
using System.Collections.Generic;
public class ModifiedStat : BaseStat {
private List<ModifyingAttribute> _mods; //A list of Attributes that modify this stat
private int _modValue; //The amount added to the baseValue from the modifiers
public ModifiedStat() {
_mods = new List<ModifyingAttribute>();
_modValue = 0;
}
public void AddModifier( ModifyingAttribute mod) {
_mods.Add (mod);
}
private void CalculateModValue() {
_modValue = 0;
if(_mods.Count > 0)
foreach(ModifyingAttribute att in _mods)
_modValue += (int)(att.attribute.AdjustedBaseValue * att.ratio);
}
public new int AdjustedBaseValue{
get { return BaseValue + BuffValue + _modValue; }
}
public struct ModifyingAttribute {
public Attribute attribute;
public float ratio;
}
}
Thanks in advance!
Answer by Dave-Carlile · May 02, 2013 at 01:59 PM
You've defined the ModifyingAttribute
struct inside the ModifiedStat
class, so in order to reference it you need to qualify it with the class it's defined in, i.e...
ModifiedStat.ModifyingAttribute healthModifier = new ModifiedStat.ModifyingAttribute();
Or you can move the struct definition outside of the class.
Oh wow, yes! Thank you very much! It just completely threw me off course and confused me! Thanks, again! (:
Answer by Jessy · May 02, 2013 at 01:58 PM
Only ModifiedStat can use ModifyingAttribute directly. Otherwise, you need to tell the compiler where to find it.
ModifiedStat.ModifyingAttribute